#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 100010
#define INF 0x3FFFFFFF
using namespace std;
int a[MAXN],w[MAXN],dp[MAXN];
int u,v,val;
int dfs(int s){
	if(s==0)
		return 0;
	if(dp[s])
		return dp[s];
	dp[s]=INF;
	for(int i=1;i<16;i++)
		if(s&(1<<i)){
			for(int j=1;j<16;j++){
				if(j!=i&&(s&(1<<j))){
					int q=i^j;
					if(s&(1<<q))
						dp[s]=min(dp[s],dfs(s^(1<<i)^(1<<j)^(1<<q))+2);
					else
						dp[s]=min(dp[s],dfs(s^(1<<i)^(1<<j)^(1<<q))+1);
				}
			}
			
		}
}
int main(){
	int S,n,ans=0;
	SF("%d",&n);
	for(int i=1;i<n;i++){
		SF("%d%d%d",&u,&v,&val);
		a[u]^=val;
		a[v]^=val;
	}
	for(int i=0;i<n;i++)
		w[a[i]]++;
	for(int i=1;i<16;i++){
		ans+=w[i]/2;
		if(w[i]%2==1)
			S^=(1<<i);
	}
	PF("%d",ans+dfs(S));
}