/*     !ya khoda!     */
#include <bits/stdc++.h>

#define ll long long
#define ld long double

#define pp push
#define po pop()
#define pb push_back
#define pf push_front
#define pob pop_back()
#define pof pop_front()
#define I insert
#define E erase

#define F first
#define S second

#define mkp make_pair
#define pll pair<ll,ll>
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define all(a) a.begin(),a.end()

#define coutghat(x)      cout<<tolower(x);
#define coutashar(x,d)   cout<<fixed<<setprecision(x)<<(ld)d
#define IOS ios_base::sync_with_stdio(false) , cin.tie(0);

#define LB(x) ((x) & -(x))
#define BIT(a , b) (((a)>>(b)) & 1)
//#define poow(a,b,M)   b?(poow((a*a)%M,b/2)%M * (b&1?a))%M:1 ;
/*==========================================================================*/
using namespace std;
ll poow(ll x,ll n,ll Mod=1e9+7) { return (n==0?1:poow(x*x%Mod,n/2)*(n&1?x:1)%Mod); }
//#pragma optimize O3
// 107,109, 211,223, 307, 401,409, 503,509, 601,607, 701,709, 809, 907, 1009
/*==========================================================================*/
const int N=2e5+10  , M=1e4+10  , SQ=320 , LG=23 , base=2;
const int mod=1e9+7 , MOD=1e9+9;
const ll  INF=1e9   , inf=1e18 , super_inf=~0ull/4;
ll n,m,a[N]  ,  cnt[16]  ,  dp[1<<16],val[1<<16]  ,  x,k;
vector<ll>vec;
/*==========================================================================*/
int main()
{
    IOS;
    cin>>n;
	for(int i=1;i<n;i++)
	{   ll v,u,w;
        cin>>v>>u>>w;
		a[v]^=w  ,  a[u]^=w;
	}
	for(int i=0;i<n;i++)   cnt[a[i]]++;


	x=cnt[0]  ,  cnt[0]=0;
	for(int i=0;i<n;i++)
	{
		if(cnt[a[i]]%2)    vec.pb(a[i]);
		x+=cnt[a[i]]/2  ,  cnt[a[i]]=0;
	}

	m=vec.size() , k=(1<<m);
	for(int i=0;i<k;i++)
		for(int j=0;j<m;j++)
			if(i>>j&1)
				val[i]^=vec[j];

	for(int i=1;i<k;i++)
	{   dp[i]=1;
		if(val[i]!=0)   continue;
		for(int j=i;j>0;j=(j-1)&i)
			if(!val[j])
				dp[i]=max(dp[i],dp[j]+dp[i^j]);
	}

	cout<<n-(dp[k-1]+x);
	return 0;
}
