// Slower C++ solution:
/*     !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;

}


// Faster C++ solution for the same problem (measured speedup: 5.267927892828395x):
#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<cmath>

#include<algorithm>

#include<ctime>

#define INF 1e9

using namespace std;

const int maxn=100010;

const double Pi=acos(-1.0);

template<class T>void read(T &x)

{

	x=0;int f=0;char ch=getchar();

	while(ch<'0'||ch>'9') {f|=(ch=='-');ch=getchar();}

	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}

	x=f?-x:x;

	return;

}

int n,num[maxn],book[21],s;

int f[(1<<17)+10],ans;

int dp(int s)

{

	if(!s)

		return 0;

	if(f[s])

		return f[s];

	f[s]=INF;

	for(int i=1;i<=15;i++)

	{

		if(!(s&(1<<i)))

			continue;

		for(int j=1;j<=15;j++)

		{

			if(i==j||!(s&(1<<j)))

				continue;

			int k=i^j;

			int t=s^(1<<i)^(1<<j)^(1<<k);

			if(s&(1<<k))

				f[s]=min(f[s],dp(t)+2);

			else

				f[s]=min(f[s],dp(t)+1);

		}

	}

	return f[s];

}

int main()

{

	scanf("%d",&n);

	for(int i=1;i<n;i++)

	{

		int a,b,c;

		scanf("%d%d%d",&a,&b,&c);

		num[a]^=c;

		num[b]^=c;

	}

	for(int i=0;i<n;i++)

		book[num[i]]++;

	for(int i=1;i<=15;i++)

	{

		ans+=(book[i]>>1);

		s|=((book[i]&1)<<i);//奇数最后剩下

	}

	printf("%d",ans+dp(s));

	return 0;

}