結果
| 問題 |
No.2822 Lights Up! (Tree Edition)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-06-26 14:51:45 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 134 ms / 2,000 ms |
| コード長 | 700 bytes |
| コンパイル時間 | 4,318 ms |
| コンパイル使用メモリ | 256,320 KB |
| 最終ジャッジ日時 | 2025-02-22 00:38:58 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 142 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
int main(){
int N;
cin >> N;
vector<int> P(N);
for (int i = 1; i < N; i++){
cin >> P[i];
P[i]--;
}
string S;
cin >> S;
S = '.' + S;
vector<int> A(N);
for (int i = 1; i < N; i++){
if (S[i] == '#'){
A[i] = 1;
}
}
atcoder::dsu uf(N);
int Q;
cin >> Q;
while (Q--){
int U, V;
cin >> U >> V;
U--;
V--;
uf.merge(U, V);
}
for (int i = 1; i < N; i++){
if (S[i] == '#'){
A[P[i]] ^= 1;
}
}
bool ok = true;
for (auto s : uf.groups()){
int x = 0;
for (int v : s){
x ^= A[v];
}
if (x == 1){
ok = false;
}
}
if (ok){
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}