#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

long long max(long long x, long long y){return (x > y ? x : y);}
long long min(long long x, long long y){return (x < y ? x : y);}
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

#define ll int
#define FOR(i,a) for(ll i=0;i<(ll)a.size();i++)
#define pb push_back
#define ld long double
#define mp make_pair
#define F first
#define S second
#define pii pair<ll,ll> 

using namespace :: std;

const ll maxn=1e5+500;
const ll inf=1e9+800;
const ll mod=1e9+7;

ll dp[1<<16];
ll xx[1<<16];
void cal(){
	xx[0]=0;
	for(ll i=1;i<(1<<16);i++){
		ll lb;
		for(ll j=0;j<16;j++){
			if((i>>j)&1){
				lb=j;
				break;
			}
		}
		xx[i]=(xx[i^(1<<lb)]^lb);
  	}
	dp[0]=0;
	for(ll i=1;i<(1<<16);i++){
		// dp[i]
		for(ll mas=i;mas>0;mas=((mas-1)&i)){
			if(xx[mas]==0)
				dp[i]=max(dp[i],dp[i^mas]+1);
		}
	}
}

vector<pii> ger[maxn];
ll cnt[16];

void dfs(ll a,ll p=-1){
	ll val=0;
	FOR(i,ger[a]){
		ll v=ger[a][i].F;
		ll w=ger[a][i].S;
		val^=w;
		if(v!=p)
		dfs(v,a);
	}
	if(p!=-1)
		cnt[val]++;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);	
	ll n;
	cin>>n;
	for(ll i=1;i<n;i++){
		ll v,u,w;
		cin>>v>>u>>w;
		ger[v].pb(mp(u,w));
		ger[u].pb(mp(v,w));
	}
	dfs(0);
	ll ans=0;
	for(ll i=1;i<16;i++){
		ans+=cnt[i]/2;
		cnt[i]%=2;
	}
	ll res=0;
	for(ll i=1;i<16;i++){
		if(cnt[i]){
			res^=i;
		}
	}
	cnt[res]++;
	cnt[res]=0;
	ans+=cnt[res]/2;
	cnt[res]%=2;

	res=0;
	ll t=0;
	for(ll i=1;i<16;i++){
		if(cnt[i]){
			res+=(1<<i);
			t++;
		}
	}
	cal();
	cout<<ans+t-dp[res];
}