結果
問題 | No.2205 Lights Out on Christmas Tree |
ユーザー | Kude |
提出日時 | 2023-02-03 21:46:15 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 87 ms / 2,000 ms |
コード長 | 1,338 bytes |
コンパイル時間 | 2,524 ms |
コンパイル使用メモリ | 228,704 KB |
実行使用メモリ | 24,128 KB |
最終ジャッジ日時 | 2023-09-15 17:27:49 |
合計ジャッジ時間 | 6,558 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,384 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 1 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 1 ms
4,380 KB |
testcase_07 | AC | 1 ms
4,384 KB |
testcase_08 | AC | 1 ms
4,380 KB |
testcase_09 | AC | 1 ms
4,380 KB |
testcase_10 | AC | 2 ms
4,380 KB |
testcase_11 | AC | 66 ms
15,560 KB |
testcase_12 | AC | 67 ms
15,544 KB |
testcase_13 | AC | 65 ms
15,544 KB |
testcase_14 | AC | 61 ms
15,668 KB |
testcase_15 | AC | 79 ms
24,128 KB |
testcase_16 | AC | 48 ms
10,580 KB |
testcase_17 | AC | 48 ms
10,572 KB |
testcase_18 | AC | 2 ms
4,376 KB |
testcase_19 | AC | 73 ms
15,368 KB |
testcase_20 | AC | 72 ms
14,796 KB |
testcase_21 | AC | 73 ms
14,732 KB |
testcase_22 | AC | 65 ms
15,952 KB |
testcase_23 | AC | 74 ms
14,804 KB |
testcase_24 | AC | 73 ms
15,148 KB |
testcase_25 | AC | 74 ms
14,776 KB |
testcase_26 | AC | 87 ms
14,888 KB |
testcase_27 | AC | 73 ms
15,612 KB |
testcase_28 | AC | 64 ms
15,892 KB |
testcase_29 | AC | 67 ms
15,812 KB |
testcase_30 | AC | 84 ms
14,988 KB |
testcase_31 | AC | 72 ms
15,600 KB |
testcase_32 | AC | 73 ms
15,028 KB |
testcase_33 | AC | 72 ms
15,092 KB |
testcase_34 | AC | 73 ms
14,892 KB |
testcase_35 | AC | 80 ms
14,804 KB |
testcase_36 | AC | 80 ms
14,884 KB |
testcase_37 | AC | 73 ms
14,832 KB |
testcase_38 | AC | 73 ms
14,836 KB |
testcase_39 | AC | 69 ms
15,268 KB |
ソースコード
#include<bits/stdc++.h> namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include<atcoder/all> #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; VVI to(n); rep(_, n - 1) { int a, b; cin >> a >> b; a--, b--; to[a].emplace_back(b); to[b].emplace_back(a); } VI c(n); rep(i, n) cin >> c[i]; if ((n - accumulate(all(c), 0)) % 2) { cout << -1 << '\n'; return 0; } int ans = 0; auto dfs = [&](auto self, int u, int p) -> bool { bool now = false; for(int v: to[u]) if (v != p) now ^= self(self, v, u); c[u] ^= now; ans += !c[u]; return !c[u]; }; if (dfs(dfs, 0, -1)) assert(false); cout << ans << '\n'; }