#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
using namespace std;

#define LL long long
#define DB double
#define MAXN 100000
#define MOD 1000000007
#define Pr pair<int,int>
#define X first
#define Y second
#define INF 1000000000000000000
#define mem(x,v) memset(x,v,sizeof(x))

LL read(){
	LL x=0,F=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*F;
}

int n,val[MAXN+5],cnt[MAXN+5],ans,st;
int dp[MAXN+5],flag[MAXN+5];

int main(){
	n=read();
	for(int i=1;i<n;i++){
		int u=read(),v=read(),w=read();
		val[u]^=w,val[v]^=w;
	}
	for(int i=0;i<n;i++)cnt[val[i]]++;
	for(int i=1;i<=15;i++)ans+=cnt[i]/2,st|=(cnt[i]&1)*(1<<(i-1));
	dp[0]=-1;
	for(int S=1;S<(1<<15);S++)dp[S]=dp[S>>1]+(S&1);
	dp[0]=0;
	for(int S=1;S<(1<<15);S++)
		for(int i=0;i<15;i++)
		if(S&(1<<i))flag[S]^=(i+1);
	for(int S=1;S<(1<<15);S++)
	if(!flag[S]){
		for(int nS=(S-1)&S;nS;nS=(nS-1)&S)
		if(!flag[nS])dp[S]=min(dp[S],dp[nS]+dp[S^nS]);
	}
	printf("%d",ans+dp[st]);
}