結果
| 問題 |
No.2205 Lights Out on Christmas Tree
|
| コンテスト | |
| ユーザー |
srjywrdnprkt
|
| 提出日時 | 2023-01-28 15:33:25 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 184 ms / 2,000 ms |
| コード長 | 705 bytes |
| コンパイル時間 | 668 ms |
| コンパイル使用メモリ | 75,668 KB |
| 最終ジャッジ日時 | 2025-02-10 07:29:28 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 |
ソースコード
#include <iostream>
#include <vector>
using namespace std;
int ans = 0;
vector<int> c;
int dfs(vector<vector<int>> &E, int from, int p){
int cnt=0;
for(auto to : E[from]){
if (p == to) continue;
cnt += dfs(E, to, from);
}
if ((cnt + c[from]) % 2 == 0){
ans++;
return 1;
}
else return 0;
}
int main(){
int N, a, b;
cin >> N;
vector<vector<int>> E(N);
c.resize(N);
for (int i=0; i<N-1; i++){
cin >> a >> b; a--; b--;
E[a].push_back(b);
E[b].push_back(a);
}
for (int i=0; i<N; i++) cin >> c[i];
if (dfs(E, 1, -1) == 1) cout << -1 << endl;
else cout << ans << endl;
return 0;
}
srjywrdnprkt