結果

問題 No.2822 Lights Up! (Tree Edition)
ユーザー achapi
提出日時 2024-06-26 14:47:02
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 623 bytes
コンパイル時間 3,653 ms
コンパイル使用メモリ 254,704 KB
最終ジャッジ日時 2025-02-22 00:38:20
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 80 WA * 62
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
int main(){
	int N;
	cin >> N;
	vector<int> P(N - 1);
	for (int i = 0; i < N - 1; i++){
		cin >> P[i];
		P[i]--;
	}
	string S;
	cin >> S;
	atcoder::dsu uf(N);
	int Q;
	cin >> Q;
	while (Q--){
		int U, V;
		cin >> U >> V;
		U--;
		V--;
		uf.merge(U, V);
	}
	vector<int> A(N);
	for (int i = 0; i < N - 1; i++){
		if (S[i] == '#'){
			A[i + 1] ^= 1;
			A[P[i]] ^= 1;
		}
	}
	bool ok = true;
	for (auto s : uf.groups()){
		int x = 0;
		for (int v : s){
			x ^= A[v];
		}
		ok |= x;
	}
	if (ok){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}
0