能过样例
#include<iostream>
#define int long long
using namespace std;
int n;
struct EDGE{
int u,v,w,nxt;
}edge[200005];
int head[100005],num;
void add(int u,int v,int w){
edge[++num]={u,v,w,head[u]};
head[u]=num;
}
int a[100005];
void dfs(int x,int fa){
for(int i=head[x];i;i=edge[i].nxt){
int v=edge[i].v;
if(v==fa)continue;
a[v]=a[x]^edge[i].w;
dfs(v,x);
}
}
int tot;
struct node{
int lc,rc,x;
}ch[3000005];
void build(int x){
int now=1;
for(int i=31;i>=0;i--){
int y=(x^(1<<i))>>i;
y%=2;
if(y==0){
if(ch[now].lc)now=ch[now].lc;
else{
ch[now].lc=++tot;
now=tot;
}
}
if(y==1){
if(ch[now].rc)now=ch[now].rc;
else{
ch[now].rc=++tot;
now=tot;
}
}
}
ch[now].x++;
}
int ans;
int query(int x){
int now=1,p=0;
for(int i=31;i>=0;i--){
p*=2;
int y=(x^(1<<i))>>i;
y%=2;
//cout<<"test - "<<x<<' '<<y<<endl;
if(y==1){
if(ch[now].lc)now=ch[now].lc,p++;
else now=ch[now].rc;
}
if(y==0){
if(ch[now].rc)now=ch[now].rc,p++;
else now=ch[now].lc;
}
}
return x^p;
}
signed main(){
cin>>n;
for(int i=1;i<n;i++){
int u,v,w;
cin>>u>>v>>w;
add(u,v,w);
add(v,u,w);
}
dfs(1,0);
tot=1;
for(int i=1;i<=n;i++)build(a[i]);
for(int i=1;i<=n;i++){//cout<<endl;
ans=max(ans,query(a[i]));
}
cout<<ans<<endl;
return 0;
}
//769275