神秘RE求调+1
查看原帖
神秘RE求调+1
602361
114514wxy楼主2023/8/16 15:08

#10 #11 RE 其它AC

#include<bits/stdc++.h>
using namespace std;
const int N=100005;
#define ll long long

ll head[N],nxt[N],ver[N],edge[N],tot=1,trie[N*100][2],maxn;
ll n;
ll sum[N];

void add(int x,int y,int w){
	nxt[++tot]=head[x],ver[tot]=y,edge[tot]=w,head[x]=tot;
}

void dfs(int x,int ed){
	
	for(int i=head[x];i;i=nxt[i]){//cout<<i<<' '<<x<<' '<<ed^1<<endl;
		if(i==(ed^1)) continue;
		int y=ver[i];//printf("%d-%d\n",x,y);
		sum[y]=sum[x]^edge[i];
		dfs(y,i);
	}
}

void insert(ll tmp){
	
	int p=1;
	for(int i=30;i>=0;--i){
		bool ch=(tmp>>i)&1;
		if(trie[p][ch]==0){
			trie[p][ch]=++tot;
		}
		p=trie[p][ch];
	}
	return;
}

ll chk(ll tmp){
	
	ll p=1,ans=0;
	for(int i=30;i>=0;--i){
		bool ch=(tmp>>i)&1;
		ch=ch^1;
		if(trie[p][ch]==0){
			ch=ch^1;
		} else {
			ans+=(1<<i);
		}
		p=trie[p][ch];
	}
	return ans;
}

ll maxx(ll aa,ll bb){
	if(aa>bb) return aa;
	return bb;
}

int main(){
	
	cin>>n;
	for(int i=1;i<n;++i){
		int x,y,w;
		cin>>x>>y>>w;
		add(x,y,w);add(y,x,w);
	}
	
	dfs(1,0);
	tot=1;
	for(int i=1;i<=n;++i){
		insert(sum[i]);
	}
	for(int i=1;i<=n;++i){
		maxn=maxx(maxn,chk(sum[i]));
	}
	cout<<maxn<<endl;
	
	return 0;
}
2023/8/16 15:08
加载中...