結果

問題 No.2800 Game on Tree Inverse
ユーザー 👑 kmjpkmjp
提出日時 2024-07-05 01:09:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 723 ms / 4,000 ms
コード長 2,564 bytes
コンパイル時間 2,570 ms
コンパイル使用メモリ 215,128 KB
実行使用メモリ 229,740 KB
最終ジャッジ日時 2024-07-05 01:09:58
合計ジャッジ時間 27,712 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
24,044 KB
testcase_01 AC 10 ms
23,936 KB
testcase_02 AC 9 ms
23,936 KB
testcase_03 AC 723 ms
222,720 KB
testcase_04 AC 503 ms
180,608 KB
testcase_05 AC 478 ms
177,476 KB
testcase_06 AC 491 ms
176,584 KB
testcase_07 AC 448 ms
174,532 KB
testcase_08 AC 440 ms
172,864 KB
testcase_09 AC 435 ms
172,176 KB
testcase_10 AC 623 ms
204,360 KB
testcase_11 AC 650 ms
218,564 KB
testcase_12 AC 613 ms
205,480 KB
testcase_13 AC 588 ms
195,692 KB
testcase_14 AC 553 ms
192,968 KB
testcase_15 AC 627 ms
209,476 KB
testcase_16 AC 543 ms
191,068 KB
testcase_17 AC 699 ms
212,460 KB
testcase_18 AC 572 ms
197,060 KB
testcase_19 AC 495 ms
179,824 KB
testcase_20 AC 646 ms
211,048 KB
testcase_21 AC 606 ms
197,360 KB
testcase_22 AC 469 ms
179,516 KB
testcase_23 AC 642 ms
203,464 KB
testcase_24 AC 555 ms
200,680 KB
testcase_25 AC 525 ms
180,828 KB
testcase_26 AC 489 ms
178,792 KB
testcase_27 AC 551 ms
202,844 KB
testcase_28 AC 489 ms
176,372 KB
testcase_29 AC 653 ms
215,620 KB
testcase_30 AC 595 ms
192,616 KB
testcase_31 AC 523 ms
188,064 KB
testcase_32 AC 694 ms
229,740 KB
testcase_33 AC 558 ms
200,688 KB
testcase_34 AC 547 ms
196,312 KB
testcase_35 AC 622 ms
212,808 KB
testcase_36 AC 10 ms
24,040 KB
testcase_37 AC 9 ms
24,064 KB
testcase_38 AC 9 ms
23,936 KB
testcase_39 AC 9 ms
23,936 KB
testcase_40 AC 10 ms
23,936 KB
testcase_41 AC 10 ms
23,936 KB
testcase_42 AC 10 ms
24,064 KB
testcase_43 AC 10 ms
24,044 KB
testcase_44 AC 9 ms
23,936 KB
testcase_45 AC 10 ms
24,044 KB
testcase_46 AC 19 ms
24,064 KB
testcase_47 AC 14 ms
25,344 KB
testcase_48 AC 12 ms
25,088 KB
testcase_49 AC 29 ms
31,340 KB
testcase_50 AC 21 ms
28,288 KB
testcase_51 AC 334 ms
123,776 KB
testcase_52 AC 35 ms
33,376 KB
testcase_53 AC 77 ms
47,104 KB
testcase_54 AC 320 ms
122,096 KB
testcase_55 AC 563 ms
180,720 KB
testcase_56 AC 422 ms
150,448 KB
testcase_57 AC 619 ms
196,328 KB
testcase_58 AC 207 ms
89,468 KB
testcase_59 AC 277 ms
108,780 KB
testcase_60 AC 198 ms
83,184 KB
testcase_61 AC 140 ms
67,020 KB
testcase_62 AC 213 ms
85,744 KB
testcase_63 AC 234 ms
93,548 KB
testcase_64 AC 94 ms
51,564 KB
testcase_65 AC 88 ms
50,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

struct BinarySumTrie {
	set<ll> V;
	ll x;
	struct node {
		ll v;
		node *nex[2];
		node() {
			nex[0]=nex[1]=NULL;v=0;
		};
		void add(ll s,int pos=20) {
			v++;
			if(pos>=0) {
				int c=(s>>pos)&1;
				if(!nex[c]) {
					nex[c]=new node();
				}
				nex[c]->add(s,pos-1);
			}
		}
		ll gr(int pos,ll x) { // sum [0,s-1]
			ll num=1LL<<(pos);
			if(x&(1LL<<pos)) {
				if(!nex[1]) return 0;
				if(nex[1]->v<num) {
					return nex[1]->gr(pos-1,x);
				}
				else {
					if(!nex[0]) return num;
					return (num)^nex[0]->gr(pos-1,x);
				}
			}
			else {
				if(!nex[0]) return 0;
				if(nex[0]->v<num) {
					return nex[0]->gr(pos-1,x);
				}
				else {
					if(!nex[1]) return num;
					return (num)^nex[1]->gr(pos-1,x);
				}
			}
			return 0;
		}
		
	};
	node root;
	BinarySumTrie() {
		x=0;
	}
	void add(ll s) {
		s^=x;
		if(V.count(s)) return;
		V.insert(s);
		root.add(s);
	}
	ll gr() {
		return root.gr(20,x);
	}
};

int N;
vector<int> E[202020];
BinarySumTrie bs[202020];
int G[202020];
vector<int> V;
void dfs(int cur,int pre) {
	ll x=0;
	bs[cur].add(0);
	FORR(e,E[cur]) if(e!=pre) {
		dfs(e,cur);
		bs[e].x^=x;
		x^=G[e];
		bs[cur].x^=G[e];
		if(bs[cur].V.size()<bs[e].V.size()) {
			swap(bs[cur],bs[e]);
		}
		FORR(v,bs[e].V) bs[cur].add(v^bs[e].x);
	}
	G[cur]=bs[cur].gr();
	
}

void dfs2(int cur,int pre,int g) {
	
	FORR(e,E[cur]) if(e!=pre) g^=G[e];
	if(g==0) V.push_back(cur+1);
	FORR(e,E[cur]) if(e!=pre) dfs2(e,cur,g^G[e]);
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N-1) {
		cin>>x>>y;
		E[x-1].push_back(y-1);
		E[y-1].push_back(x-1);
	}
	dfs(0,0);
	
	if(G[0]) {
		dfs2(0,0,0);
		cout<<"Alice"<<endl;
		cout<<V.size()<<endl;
		sort(ALL(V));
		FORR(v,V) cout<<v<<" ";
		cout<<endl;
	}
	else {
		cout<<"Bob"<<endl;
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0