#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9,LOGN = 31,K = N << 1;
struct edge{
int to,cost,nex;
} e[K];
int head[K],ecnt;
int xor_num[K];
int n,ans;
void addedge(int u,int v,int w){
ecnt++;
e[ecnt] = (edge){v,w,head[u]};
head[u] = ecnt;
}
void dfs(int u,int fa,int num){
xor_num[u] = num;
for(int i = head[u];i;i = e[i].nex){
int v = e[i].to,w = e[i].cost;
if(v == fa)
continue;
dfs(v,u,num ^ w);
}
}
struct node{
int child[2];
} trie[K];
int node_cnt;
void insert(int x){
int u = 0;
for(int i = LOGN;i >= 0;i--){
int c = (x >> i) & 1;
if(!trie[u].child[c])
trie[u].child[c] = ++node_cnt;
u = trie[u].child[c];
}
}
int query(int x){
int u = 0,ans = 0;
for(int i = LOGN;i >= 0;i--){
int c = (x >> i) & 1;
if(trie[u].child[!c]){
u = trie[u].child[!c];
ans = (ans << 1) | 1;
}
else{
u = trie[u].child[c];
ans <<= 1;
}
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin >> n;
for(int i = 1;i <= n - 1;i++){
int u,v,w;
cin >> u >> v >> w;
addedge(u,v,w);
addedge(v,u,w);
}
dfs(1,0,0);
for(int i = 1;i <= n;i++)
insert(xor_num[i]);
for(int i = 1;i <= n;i++)
ans = max(ans,query(xor_num[i]));
cout << ans;
return 0;
}