#include <iostream>
#include <set>
#include <unordered_set>
#include <vector>
#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 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);

    long long ans=0;
    set<long long> s;
    for(int i = 1; i <= n; i++) {
        long long mask = 0, upper = 0;
        for(int j = 60; j >= 0; j--) {
            if((dist[i]&(1LL<<j))==0) mask|=(1LL<<j);
            upper=mask|((1LL<<j)-1);
            set<long long>::iterator l = s.lower_bound(mask), r = s.upper_bound(upper);
            if(l==r) {
                mask^=(1LL<<j);
                continue;
            }
        }
        ans=max(ans, dist[i]^mask);
        s.insert(dist[i]);
    }
    cout<<ans<<endl;
}