結果
問題 | No.2800 Game on Tree Inverse |
ユーザー |
👑 ![]() |
提出日時 | 2024-06-21 04:28:36 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 595 ms / 4,000 ms |
コード長 | 2,954 bytes |
コンパイル時間 | 3,326 ms |
コンパイル使用メモリ | 220,668 KB |
実行使用メモリ | 86,812 KB |
最終ジャッジ日時 | 2024-06-21 04:29:08 |
合計ジャッジ時間 | 26,778 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 508 ms
38,272 KB |
testcase_04 | AC | 549 ms
84,756 KB |
testcase_05 | AC | 514 ms
86,120 KB |
testcase_06 | AC | 546 ms
85,476 KB |
testcase_07 | AC | 495 ms
86,812 KB |
testcase_08 | AC | 483 ms
86,116 KB |
testcase_09 | AC | 415 ms
85,460 KB |
testcase_10 | AC | 504 ms
53,516 KB |
testcase_11 | AC | 523 ms
84,976 KB |
testcase_12 | AC | 501 ms
84,500 KB |
testcase_13 | AC | 595 ms
85,724 KB |
testcase_14 | AC | 532 ms
85,688 KB |
testcase_15 | AC | 513 ms
85,288 KB |
testcase_16 | AC | 565 ms
85,788 KB |
testcase_17 | AC | 505 ms
52,924 KB |
testcase_18 | AC | 574 ms
84,852 KB |
testcase_19 | AC | 490 ms
85,948 KB |
testcase_20 | AC | 516 ms
85,544 KB |
testcase_21 | AC | 579 ms
84,836 KB |
testcase_22 | AC | 532 ms
86,356 KB |
testcase_23 | AC | 491 ms
86,380 KB |
testcase_24 | AC | 546 ms
52,940 KB |
testcase_25 | AC | 529 ms
84,992 KB |
testcase_26 | AC | 548 ms
85,104 KB |
testcase_27 | AC | 455 ms
85,576 KB |
testcase_28 | AC | 473 ms
85,052 KB |
testcase_29 | AC | 510 ms
52,044 KB |
testcase_30 | AC | 511 ms
52,732 KB |
testcase_31 | AC | 506 ms
86,620 KB |
testcase_32 | AC | 487 ms
53,288 KB |
testcase_33 | AC | 507 ms
84,956 KB |
testcase_34 | AC | 489 ms
85,604 KB |
testcase_35 | AC | 500 ms
85,344 KB |
testcase_36 | AC | 2 ms
6,944 KB |
testcase_37 | AC | 2 ms
6,944 KB |
testcase_38 | AC | 2 ms
6,944 KB |
testcase_39 | AC | 2 ms
6,940 KB |
testcase_40 | AC | 2 ms
6,944 KB |
testcase_41 | AC | 2 ms
6,944 KB |
testcase_42 | AC | 2 ms
6,944 KB |
testcase_43 | AC | 2 ms
6,944 KB |
testcase_44 | AC | 2 ms
6,944 KB |
testcase_45 | AC | 2 ms
6,944 KB |
testcase_46 | AC | 2 ms
6,940 KB |
testcase_47 | AC | 5 ms
6,940 KB |
testcase_48 | AC | 4 ms
6,940 KB |
testcase_49 | AC | 16 ms
6,944 KB |
testcase_50 | AC | 10 ms
6,940 KB |
testcase_51 | AC | 285 ms
45,388 KB |
testcase_52 | AC | 20 ms
6,940 KB |
testcase_53 | AC | 50 ms
10,060 KB |
testcase_54 | AC | 249 ms
44,988 KB |
testcase_55 | AC | 425 ms
51,744 KB |
testcase_56 | AC | 371 ms
47,584 KB |
testcase_57 | AC | 483 ms
51,944 KB |
testcase_58 | AC | 160 ms
26,048 KB |
testcase_59 | AC | 214 ms
27,428 KB |
testcase_60 | AC | 140 ms
26,064 KB |
testcase_61 | AC | 111 ms
15,660 KB |
testcase_62 | AC | 157 ms
26,224 KB |
testcase_63 | AC | 174 ms
26,348 KB |
testcase_64 | AC | 65 ms
14,992 KB |
testcase_65 | AC | 62 ms
14,868 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; const int D = 18; struct node{ int sum = 0; int depth = D - 1; array<int, 2> to = {-1, -1}; }; int f(int a,int d){ return (a & (1 << d)) != 0; } vector<node> nodes; struct binary{ int root; int C = 0; binary(){ root = nodes.size(); node tmp; nodes.push_back(tmp); } bool get(int a){ a ^= C; int ind = root; while (nodes[ind].depth != -1){ int b = f(a, nodes[ind].depth); if (nodes[ind].to[b] == -1) return false; ind = nodes[ind].to[b]; } return true; } void set(int a){ if (get(a)) return; a ^= C; int ind = root; while (nodes[ind].depth != -1){ int b = f(a, nodes[ind].depth); if (nodes[ind].to[b] == -1){ nodes[ind].to[b] = nodes.size(); node tmp; tmp.depth = nodes[ind].depth - 1; nodes.push_back(tmp); } ind = nodes[ind].to[b]; nodes[ind].sum++; } } int mim(){ int ans = 0; int ind = root; while (ind != -1 && nodes[ind].depth != -1){ int b = f(C, nodes[ind].depth); int d = nodes[ind].to[b]; if (d != -1 && nodes[d].sum == (1 << nodes[ind].depth)){ ans += nodes[d].sum; ind = nodes[ind].to[1 - b]; } else{ ind = d; } } return ans; } vector<int> get_list(){ vector<int> res; auto f = [&](auto self, int ind, int val) -> void { if (ind == -1) return; if (nodes[ind].depth == -1){ res.push_back(val ^ C); return; } for (int i = 0; i < 2; i++){ self(self, nodes[ind].to[i], val + i * (1 << nodes[ind].depth)); } }; f(f, root, 0); return res; } }; int main(){ int N; cin >> N; vector<vector<int>> G(N); for (int i = 0; i < N - 1; i++){ int a, b; cin >> a >> b; a--, b--; G[a].push_back(b); G[b].push_back(a); } vector<int> order = {0}, pare(N, -1); pare[0] = -2; for (int i = 0; i < N; i++){ int a = order[i]; for (auto x : G[a]) if (pare[x] == -1){ order.push_back(x); pare[x] = a; } } vector<binary> dp(N); vector<int> val(N), ans, wei(N, 1); for (int i = N - 1; i >= 0; i--){ int a = order[i]; int ind = -1; int sum = 0; for (auto x : G[a]) if (pare[x] == a){ sum ^= val[x]; wei[a] += wei[x]; if (ind == -1 || wei[x] > wei[ind]) ind = x; } if (ind != -1){ dp[ind].C ^= (sum ^ val[ind]); swap(dp[ind], dp[a]); } for (auto x : G[a]) if (pare[x] == a && x != ind){ dp[x].C ^= (sum ^ val[x]); for (auto y : dp[x].get_list()){ dp[a].set(y); } } dp[a].set(sum); val[a] = dp[a].mim(); } auto dfs = [&](auto self, int ind, int v) -> void { for (auto x : G[ind]) if (pare[x] == ind){ v ^= val[x]; } if (v == 0) ans.push_back(ind + 1); for (auto x : G[ind]) if (pare[x] == ind){ self(self, x, v ^ val[x]); } }; dfs(dfs, 0, 0); cout << "Alice\n"; cout << ans.size() << "\n"; sort(ans.begin(), ans.end()); for (int i = 0; i < (int)ans.size(); i++){ if (i) cout << " "; cout << ans[i]; } cout << endl; return 0; }