//It is made by M_sea
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#define re register
using namespace std;

inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int N=200000+10;

int w[N],cnt[20],f[1<<16],sxor[1<<16];

int main() {
    int n=read();
    for (re int i=1;i<n;++i) {
        int u=read()+1,v=read()+1,val=read();
        w[u]^=val,w[v]^=val;
    }
    for (re int i=1;i<=n;++i) ++cnt[w[i]];
    int ans=0,s=0;
    for (re int i=1;i<=15;++i) ans+=cnt[i]/2,s|=(cnt[i]&1)<<(i-1);
    for (re int i=1;i<(1<<15);++i) f[i]=f[i>>1]+(i&1);
    for (re int i=1;i<(1<<15);++i) --f[i];
    for (re int i=1;i<(1<<15);++i)
        for (re int j=1;j<=15;++j)
            if (i&(1<<(j-1))) sxor[i]^=j;
    for (re int i=1;i<(1<<15);++i) {
        if (sxor[i]) continue;
        for (re int j=i&(i-1);j;j=(j-1)&i)
            if (!sxor[j]) f[i]=min(f[i],f[j]+f[i^j]);
    }
    printf("%d\n",ans+f[s]);
    return 0;
}