結果
問題 | No.2205 Lights Out on Christmas Tree |
ユーザー |
|
提出日時 | 2023-02-09 21:39:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 85 ms / 2,000 ms |
コード長 | 932 bytes |
コンパイル時間 | 1,938 ms |
コンパイル使用メモリ | 199,512 KB |
最終ジャッジ日時 | 2025-02-10 11:49:35 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 |
ソースコード
#include <bits/stdc++.h>using i64 = long long;int main() {std::ios::sync_with_stdio(false);std::cin.tie(nullptr);int n;std::cin >> n;std::vector<std::vector<int>> adj(n);for (int i = 1; i < n; i++) {int x, y;std::cin >> x >> y;x--, y--;adj[x].push_back(y);adj[y].push_back(x);}std::vector<int> c(n);for (int i = 0; i < n; i++) {std::cin >> c[i];}int ans = 0;auto dfs = [&](auto self, int x, int p) -> void {for (auto y : adj[x]) {if (y == p) {continue;}self(self, y, x);if (c[y] == 0) {c[y] ^= 1;c[x] ^= 1;ans++;}}};dfs(dfs, 0, -1);if (c[0] == 0) {ans = -1;}std::cout << ans << "\n";return 0;}