結果

問題 No.2800 Game on Tree Inverse
ユーザー 👑 kmjpkmjp
提出日時 2024-07-05 00:33:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,655 bytes
コンパイル時間 2,555 ms
コンパイル使用メモリ 216,508 KB
実行使用メモリ 274,840 KB
最終ジャッジ日時 2024-07-05 00:34:28
合計ジャッジ時間 30,732 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
25,564 KB
testcase_01 WA -
testcase_02 AC 11 ms
25,496 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 537 ms
242,036 KB
testcase_08 AC 535 ms
240,152 KB
testcase_09 AC 488 ms
239,420 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
権限があれば一括ダウンロードができます

ソースコード

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];
		BinarySumTrie *bst;
		node() {
			nex[0]=nex[1]=NULL;v=0;
			bst=NULL;
		};
		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]->bst=this->bst;
				}
				nex[c]->add(s,pos-1);
			}
		}
		ll gr(int pos=20) { // sum [0,s-1]
			if(pos<0) return 0;
			
			ll num=1LL<<pos;
			if(bst->x&(1LL<<pos)) {
				if(!nex[1]) return 0;
				if(nex[1]->v<num) {
					return nex[1]->gr(pos-1);
				}
				else {
					if(!nex[0]) return num;
					return num^nex[0]->gr(pos-1);
				}
			}
			else {
				if(!nex[0]) return 0;
				if(nex[0]->v<num) {
					return nex[0]->gr(pos-1);
				}
				else {
					if(!nex[1]) return num;
					return num^nex[1]->gr(pos-1);
				}
			}
			return 0;
		}
		
	};
	node root;
	BinarySumTrie() {
		x=0;
		root.bst=this;
	}
	void add(ll s) {
		s^=x;
		if(V.count(s)) return;
		V.insert(s);
		root.add(s);
	}
	ll gr() {
		return root.gr();
	}
};

int N;
vector<int> E[202020];
BinarySumTrie bs[202020];
int G[202020];
vector<int> V;
void dfs(int cur,int pre) {
	int 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