#include<algorithm>
#include<cstring>
#include<cstdio>
#define ll long long
#define qwq 100007
int n;
int val[qwq];
bool Map[30];
int ans;
int dp[1<<20];
int dfs(int s){
	if(s==0)return 0;
	if(dp[s]!=0x3f3f3f3f)return dp[s];
	for(int i=1;i<=16;++i){
		if(!(s&(1<<i)))continue;
		for(int j=1;j<=16;++j){
			if(i==j)continue;
			if(!(s&(1<<j)))continue;
			int x=i^j;
			if(s&(1<<x))dp[s]=std::min(dp[s],dfs(s^(1<<i)^(1<<j)^(1<<x))+2);
			else dp[s]=std::min(dp[s],dfs(s^(1<<i)^(1<<j)^(1<<x))+1);
		}
	}
	return dp[s];
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;++i){
		int a,b,v;
		scanf("%d%d%d",&a,&b,&v);
		++a;++b;
		val[a]^=v;val[b]^=v;
	}
	for(int i=1;i<=n;++i){
		if(val[i]==0)continue;
		if(!Map[val[i]])Map[val[i]]=true;
		else ++ans,Map[val[i]]=false;
	}
	memset(dp,0x3f,sizeof(dp));
	int s=0;
	for(int i=1;i<=16;++i){
		s+=Map[i]<<i;
	}
	printf("%d\n",ans+dfs(s));
	return 0;
} 