#include <iostream>
#include <vector>
#include <unordered_set>
#define endl '\n'

using namespace std;

long long dist[100005];
int n;
vector<pair<int,long long>> v[100005];

void dfs(int i, int par) {
    for(auto &x : v[i]) {
        if(x.first==par) continue;
        dist[x.first]=dist[i]^x.second;
        dfs(x.first, i);
    }
}

int l[100005*62], r[100005*62];
int sz[100005*62];
int cnt=1;
void insert(long long x) {
    int curr = 1;
    for(int i = 60; i >= 0; i--) {
        bool bit = x&(1LL<<i);
        int child = (bit?r[curr]:l[curr]);
        if(!child) {
            cnt++;
            if(bit) r[curr]=cnt;
            else l[curr]=cnt;
            child = cnt;
        }
        curr=child;
    }
}

int main() {
    cin >> n;
    for(int i = 1; i <= n-1; i++) {
        int a,b; long long w; cin >> a >> b >> w;
        v[a].push_back({b, w});
        v[b].push_back({a, w});
    }
    dfs(1, -1);

    for(int i = 1; i <= n; i++) insert(dist[i]);

    long long ans=0;
    for(int i = 1; i <= n; i++) {
        int curr = 1;
        long long val=0;
        for(int j = 60; j >= 0; j--) {
            bool bit = !(dist[i]&(1LL<<j));
            int child = (bit?r[curr]:l[curr]);
            if(!child) {
                bit=!bit;
                child = (bit?r[curr]:l[curr]);
            }
            
            if(bit) val|=(1LL<<j);
            curr=child;
        }
        ans=max(ans, dist[i]^val);
    }
    cout<<ans;
}