結果
問題 | No.2800 Game on Tree Inverse |
ユーザー | shobonvip |
提出日時 | 2024-06-26 01:20:11 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 735 ms / 4,000 ms |
コード長 | 3,041 bytes |
コンパイル時間 | 2,665 ms |
コンパイル使用メモリ | 215,508 KB |
実行使用メモリ | 150,196 KB |
最終ジャッジ日時 | 2024-06-26 01:20:39 |
合計ジャッジ時間 | 23,399 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 735 ms
63,856 KB |
testcase_04 | AC | 351 ms
88,100 KB |
testcase_05 | AC | 396 ms
108,224 KB |
testcase_06 | AC | 383 ms
119,208 KB |
testcase_07 | AC | 420 ms
138,032 KB |
testcase_08 | AC | 389 ms
149,148 KB |
testcase_09 | AC | 415 ms
150,196 KB |
testcase_10 | AC | 432 ms
82,876 KB |
testcase_11 | AC | 641 ms
120,348 KB |
testcase_12 | AC | 520 ms
104,104 KB |
testcase_13 | AC | 423 ms
100,576 KB |
testcase_14 | AC | 399 ms
108,704 KB |
testcase_15 | AC | 565 ms
113,460 KB |
testcase_16 | AC | 421 ms
109,436 KB |
testcase_17 | AC | 559 ms
92,080 KB |
testcase_18 | AC | 406 ms
90,568 KB |
testcase_19 | AC | 360 ms
99,092 KB |
testcase_20 | AC | 562 ms
101,196 KB |
testcase_21 | AC | 432 ms
101,416 KB |
testcase_22 | AC | 415 ms
109,252 KB |
testcase_23 | AC | 536 ms
99,100 KB |
testcase_24 | AC | 474 ms
86,660 KB |
testcase_25 | AC | 354 ms
88,580 KB |
testcase_26 | AC | 356 ms
100,196 KB |
testcase_27 | AC | 551 ms
112,124 KB |
testcase_28 | AC | 386 ms
119,056 KB |
testcase_29 | AC | 575 ms
73,628 KB |
testcase_30 | AC | 384 ms
85,456 KB |
testcase_31 | AC | 442 ms
116,704 KB |
testcase_32 | AC | 692 ms
100,604 KB |
testcase_33 | AC | 474 ms
105,384 KB |
testcase_34 | AC | 515 ms
136,452 KB |
testcase_35 | AC | 567 ms
102,672 KB |
testcase_36 | AC | 3 ms
6,944 KB |
testcase_37 | AC | 3 ms
6,940 KB |
testcase_38 | AC | 2 ms
6,940 KB |
testcase_39 | AC | 3 ms
6,940 KB |
testcase_40 | AC | 2 ms
6,940 KB |
testcase_41 | AC | 2 ms
6,944 KB |
testcase_42 | AC | 2 ms
6,944 KB |
testcase_43 | AC | 2 ms
6,940 KB |
testcase_44 | AC | 2 ms
6,944 KB |
testcase_45 | AC | 2 ms
6,940 KB |
testcase_46 | AC | 2 ms
6,944 KB |
testcase_47 | AC | 4 ms
6,940 KB |
testcase_48 | AC | 4 ms
6,940 KB |
testcase_49 | AC | 14 ms
6,940 KB |
testcase_50 | AC | 9 ms
6,940 KB |
testcase_51 | AC | 218 ms
47,212 KB |
testcase_52 | AC | 18 ms
7,296 KB |
testcase_53 | AC | 44 ms
13,184 KB |
testcase_54 | AC | 212 ms
46,592 KB |
testcase_55 | AC | 385 ms
72,304 KB |
testcase_56 | AC | 275 ms
58,880 KB |
testcase_57 | AC | 390 ms
79,436 KB |
testcase_58 | AC | 134 ms
32,128 KB |
testcase_59 | AC | 179 ms
40,704 KB |
testcase_60 | AC | 143 ms
29,312 KB |
testcase_61 | AC | 98 ms
22,272 KB |
testcase_62 | AC | 128 ms
30,720 KB |
testcase_63 | AC | 143 ms
33,920 KB |
testcase_64 | AC | 53 ms
15,488 KB |
testcase_65 | AC | 52 ms
15,360 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; template <int MAX_LOG> struct binary_trie { struct node { node *ch[2] = {nullptr, nullptr}; int cnt = 0; node() {} }; public: node *root = nullptr; int xor_all = 0; binary_trie() : root(nullptr) {} void insert(int val){ val ^= xor_all; root = insert(root, val); } int count(int val){ node* now_node = root; val ^= xor_all; for (int b=MAX_LOG-1; b>=0; b--){ if (now_node == nullptr) break; now_node = now_node->ch[(val>>b)&1]; } return size(now_node); } int xth(int x){ node* now_node = root; assert(now_node != nullptr); int ret = 0; for (int b=MAX_LOG-1; b>=0; b--){ bool f = (xor_all>>b)&1; if (size(now_node->ch[f]) <= x){ x -= size(now_node->ch[f]); now_node = now_node->ch[f^1]; ret = (ret<<1)|(f^1); }else{ assert(1 <= size(now_node->ch[f])); now_node = now_node->ch[f]; ret = (ret<<1)|f; } } return ret ^ xor_all; } int mex(){ int ub = root->cnt; int lb = -1; while (ub - lb > 1){ int t = (ub + lb) / 2; if (xth(t) == t) lb = t; else ub = t; } return lb + 1; } private: node* insert(node* t, int val, int b = MAX_LOG - 1){ if (t == nullptr) t = new node; t->cnt++; if (b < 0) return t; bool f = (val>>b)&1; t->ch[f] = insert(t->ch[f], val, b-1); return t; } int size(node* t){ if (t == nullptr) return 0; return t->cnt; } }; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<vector<int>> ikeru(n, vector<int>(0)); for (int i=0; i<n-1; i++){ int u, v; cin >> u >> v; u--; v--; ikeru[u].push_back(v); ikeru[v].push_back(u); } vector<int> dp(n); vector<binary_trie<20>> ep(n); auto dfs1 = [&](auto self, int i, int p) -> void { int x = 0; int mxval = 0; int mxind = i; for (int j: ikeru[i]){ if (j == p) continue; self(self, j, i); x ^= dp[j]; if (mxval < ep[j].root->cnt) { mxval = ep[j].root->cnt; mxind = j; } } ep[mxind].xor_all ^= dp[mxind]^x; for (int j: ikeru[i]){ if (j == p) continue; if (j == mxind) { continue; }else{ int mxz = ep[j].root->cnt; for (int z=0; z<mxz; z++){ int tar = ep[j].xth(z); if (ep[mxind].count(tar^x^dp[j]) == 0){ ep[mxind].insert(tar^x^dp[j]); } } } } if (ep[mxind].count(x) == 0){ ep[mxind].insert(x); } swap(ep[mxind], ep[i]); dp[i] = ep[i].mex(); }; dfs1(dfs1, 0, -1); vector<int> ans; auto dfs2 = [&](auto self, int i, int p, int g) -> void { int x = g; for (int j: ikeru[i]){ if (j == p) continue; x ^= dp[j]; } if (x == 0) ans.push_back(i); for (int j: ikeru[i]){ if (j == p) continue; self(self, j, i, x^dp[j]); } }; dfs2(dfs2, 0, -1, 0); if (ans.empty()){ cout << "Bob\n"; }else{ cout << "Alice\n"; int k = ans.size(); sort(ans.begin(), ans.end()); cout << k << '\n'; for (int x: ans){ cout << x+1 << ' '; } cout << '\n'; } }