// Original C++ solution (slower):
#include <bits/stdc++.h>

#define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);

#define pb push_back

#define eb emplace_back

#define sz(V) ((int)(V).size())

#define befv(V) ((V)[(sz(V)-2)])

#define allv(V) ((V).begin()),((V).end())

#define sorv(V) sort(allv(V))

#define revv(V) reverse(allv(V))

#define univ(V) (V).erase(unique(allv(V)),(V).end())

#define clv(V) (V).clear()

#define upmin(a,b) (a)=min((a),(b))

#define upmax(a,b) (a)=max((a),(b))

#define rb(x) ((x)&(-(x)))

#define INF (0x3f3f3f3f)

#define INFLL (0x3f3f3f3f3f3f3f3fll)

using namespace std;

typedef long long ll;

typedef long double ld;

typedef pair<int, int> pii;



const int MAXN = 100005;



vector<int> KV[16];

int dp[1<<15];



int B[16];

int A[MAXN];



int N, Ans;



int main() {

	ios::sync_with_stdio(false);



	cin >> N;

	for(int i = 1, a, b, c; i < N; i++) {

		cin >> a >> b >> c;

		a++; b++;

		A[a] ^= c;

		A[b] ^= c;

	}

	for(int i = 1; i <= N; i++) B[A[i]]++;



	Ans = B[0]; B[0] = 0;

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

		Ans += B[i]/2;

		B[i] &= 1;

	}



	for(int key = 1; key < (1<<15); key++) {

		int mxbit = 0, sum = 0;

		for(int i = 0; i < 15; i++) if(key & (1<<i)) {

			mxbit = i;

			sum ^= i+1;

		}

		if(sum) continue;

		KV[mxbit].eb(key);

	}



	int master = 0;

	for(int i = 0; i < 15; i++) B[i] = B[i+1];

	for(int i = 0; i < 15; i++) if(B[i]) master |= 1<<i;



	dp[0] = 1;

	for(int i = 0; i < 15; i++) if(master & (1<<i)) {

		for(int key = 0; key < (1<<i); key++) {

			int ret = dp[key];

			if(!ret) continue;

			if(key != (master & key)) continue;

			for(int v : KV[i]) {

				if((key & v) || v != (master & v)) continue;

				upmax(dp[key | v], ret + 1);

			}

		}

	}



	Ans += dp[master] - 1;



	cout << (N - Ans) << endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);

#define pb push_back

#define eb emplace_back

#define sz(V) ((int)(V).size())

#define befv(V) ((V)[(sz(V)-2)])

#define allv(V) ((V).begin()),((V).end())

#define sorv(V) sort(allv(V))

#define revv(V) reverse(allv(V))

#define univ(V) (V).erase(unique(allv(V)),(V).end())

#define clv(V) (V).clear()

#define upmin(a,b) (a)=min((a),(b))

#define upmax(a,b) (a)=max((a),(b))

#define rb(x) ((x)&(-(x)))

#define INF (0x3f3f3f3f)

#define INFLL (0x3f3f3f3f3f3f3f3fll)

using namespace std;

typedef long long ll;

typedef long double ld;

typedef pair<int, int> pii;



const int MAXN = 100005;



vector<pii> KV;



int B[16];

int A[MAXN];



int N, Ans;



int main() {

	ios::sync_with_stdio(false);



	cin >> N;

	for(int i = 1, a, b, c; i < N; i++) {

		cin >> a >> b >> c;

		a++; b++;

		A[a] ^= c;

		A[b] ^= c;

	}

	for(int i = 1; i <= N; i++) B[A[i]]++;



	Ans = B[0]; B[0] = 0;

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

		Ans += B[i]/2;

		B[i] &= 1;

	}



	int master = 0;

	for(int i = 0; i < 15; i++) B[i] = B[i+1];

	for(int i = 0; i < 15; i++) if(B[i]) master |= 1<<i;



	for(int key = 1; key <= master; key++) {

		if((key & master) != key) continue;

		int sum = 0, cnt = 0;

		for(int i = 0; i < 15; i++) if(key & (1<<i)) {

			cnt++; sum ^= i+1;

		}

		if(sum) continue;

		KV.eb(cnt, key);

	}



	sorv(KV);



	int used = 0;

	for(auto &p : KV) {

		if(used & p.second) continue;

		used |= p.second;

		Ans++;

	}



	cout << (N - Ans) << endl;

	return 0;

}

// Fastest known solution for this problem: