开了O2之后变成WA了
by 114514wxy @ 2023-08-16 15:08:50
@[114514wxy](/user/602361) `const int N=100005;` should be `const int N=200005;`
```cpp
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
#define ll long long
ll head[N],nxt[N],ver[N],edge[N],tot=1,trie[N*60][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;
}
```
by ksun48 @ 2023-08-16 15:21:11
@[ksun48](/user/822700) thx!谢大佬 已关
by 114514wxy @ 2023-08-16 15:27:23