#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e5 + 7;
const int maxlog = 61;
vector<pair<int, int>> g[maxn];
int h[maxn];
void dfs(int u, int xorr, int par)
{
    h[u] = xorr;
    for (auto x : g[u])
    {
        if (x.first == par)
            continue;
        dfs(x.first, xorr ^ x.second, u);
    }
    return;
}
int n;
unordered_map<int, bool> dali;
inline bool check(int xorr, int pos)
{
    dali.clear();
    int num = (1LL << maxlog) - (1LL << pos);
    for (int i = 1; i <= n; i++)
    {
        dali[(h[i] & num)] = true;
        int target = (h[i] & num) ^ xorr;
        if (dali[target])
        {
            return true;
        }
    }
    return false;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n;
    for (int i = 0; i < n - 1; i++)
    {
        int a, b, w;
        cin >> a >> b >> w;
        g[a].push_back({b, w});
        g[b].push_back({a, w});
    }
    dfs(1, 0, -1);
    int maxor = 0;
    for (int i = maxlog - 1; i >= 0; i--)
    {
        maxor += (1LL << i);
        if (!check(maxor, i))
        {
            maxor -= (1LL << i);
        }
    }
    cout << maxor << endl;

    return 0;
}
