#include <bits/stdc++.h>
using namespace std;
inline int read()
{int x=0;
char c=getchar();
while (c<'0'||c>'9') c=getchar();
while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
return x;
}
int x[100005],num[17],o[17],cnt=0;
int dp[32769],f[32769],p[32769];
inline int max(int a,int b)
{return a>b?a:b;}
int main (){
	int a,b,c,i,maxn=0,n,j;
	n=read();
	for (i=1;i<n;i++)
	{a=read()+1;b=read()+1;c=read();
	x[a]^=c;x[b]^=c;
	}
	for (i=1;i<=n;i++)
	{num[x[i]]++;}
	maxn=num[0];
	for (i=1;i<=15;i++)
	{maxn+=(num[i]>>1);
	if (num[i]&1) {o[cnt++]=i;}
	}
	for (i=0;i<cnt;i++) p[(1<<i)]=i;
	for (i=1;i<(1<<cnt);i++)
	{f[i]=f[i-(i&(-i))]^o[p[i&(-i)]];}
	for (i=1;i<(1<<cnt);i++)
	{for (j=i;j;j=(j-1)&i)
	{if (f[j]) continue;
	dp[i]=max(dp[i],dp[i^j]+1);
	}
	}
	maxn+=dp[(1<<cnt)-1];
	printf ("%d\n",n-maxn);
	return 0;
}
	
	
	
	
	
	
	