結果
問題 | No.2800 Game on Tree Inverse |
ユーザー |
|
提出日時 | 2024-06-28 23:26:53 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,469 bytes |
コンパイル時間 | 4,061 ms |
コンパイル使用メモリ | 272,828 KB |
実行使用メモリ | 68,976 KB |
最終ジャッジ日時 | 2024-06-28 23:27:11 |
合計ジャッジ時間 | 16,319 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 15 WA * 49 |
ソースコード
#include <bits/stdc++.h> #define mp make_pair #define pb push_back using namespace std; using ll = long long int; template<typename T> ostream& operator+(ostream& out, const vector<T> &vec){ for(const auto &x : vec){ out<<x<<" "; } out<<"\n"; return out; } template<typename T> ostream& operator*(ostream& out, const vector<T> &vec){ for(const auto &x : vec){ out+x; } return out; } template<typename T> istream& operator>>(istream& in, vector<T> &vec){ for(auto &x : vec){ in>>x; } return in; } struct my_set{ int offset = 0; set<int> s; auto view(){ return s | views::transform([&](int x){ return x ^ offset; }); } void add(int elem){ s.insert(elem ^ offset); } void add_offset(int more_offset){ offset ^= more_offset; } bool has(int elem){ return s.count(elem ^ offset); } int size() const { return s.size(); } void add_set(my_set &other){ if(other.size() > size()) swap(*this, other); for(int x : other.view()) add(x); } }; void solve(){ int n; cin>>n; vector<vector<int>> t(n); for(int i=1;i<n;i++){ int u,v; cin>>u>>v; --u; --v; t[u].push_back(v); t[v].push_back(u); } vector<my_set> grundy_vals(n); vector<int> grundy(n); vector<int> sub(n); auto dfs = [&](int u, int p, auto&& dfs) -> void { int ch = 0; int grundy_xor = 0; for(int v : t[u]){ if(v == p) continue; dfs(v, u, dfs); grundy_xor ^= grundy[v]; sub[u] += sub[v]; ch++; } if(ch == 0){ grundy_vals[u].add(0); grundy[u] = 1; return; } sort(t[u].begin(), t[u].end(), [&](int a, int b){ return grundy_vals[a].size() > grundy_vals[b].size(); }); for(auto &v : t[u]){ if(v == p) continue; grundy_vals[v].add_offset(grundy_xor ^ grundy[v]); grundy_vals[u].add_set(grundy_vals[v]); } sort(t[u].begin(), t[u].end(), [&](int a, int b){ return sub[a] > sub[b]; }); if(ch == 1){ grundy_vals[u].add(grundy[t[u][0]]); int mex = grundy[t[u][0]]; while(grundy_vals[u].has(mex)) mex++; grundy[u] = mex; return; } int max_mex_diff = 1; while(max_mex_diff <= sub[t[u][1]]) max_mex_diff <<= 1; max_mex_diff *= 2; grundy_vals[u].add(grundy_xor); int mex = max(0, grundy[t[u][0]] - max_mex_diff); while(grundy_vals[u].has(mex)) mex++; grundy[u] = mex; }; dfs(0, -1, dfs); vector<int> res; auto dfs2 = [&](int u, int p, int c_xor, auto&& dfs) -> void { int grundy_xor = 0; for(int v : t[u]){ if(v == p) continue; grundy_xor ^= grundy[v]; } if((grundy_xor ^ c_xor) == 0){ res.push_back(u + 1); } for(int v : t[u]){ if(v == p) continue; dfs(v, u, grundy_xor ^ c_xor ^ grundy[v], dfs); } }; dfs2(0, -1, 0, dfs2); if(res.size() == 0){ cout<<"Bob\n"; return; } cout<<"Alice\n"; cout<<res.size()<<"\n"; cout+res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }