/*
	将边异或转化成点异或
	最后状压 dp 即可 
*/
#include <iostream>
#include <cstring>
#include <cstdio>
#define N 100005

using namespace std;

const int upp = 1 << 16;

int n, ans, fin;
int val[N], f[upp], cnt[16];
bool legal[upp];

inline int bitcnt(int x) {
	int res = 0;
	for(int i = x; i; i -= i & -i)
		++res;
	return res;
}

int main() {
	scanf("%d", &n);
	for(int i = 1, u, v, w; i < n; ++i) {
		scanf("%d %d %d", &u, &v, &w);
		++u, ++v;
		val[u] ^= w, val[v] ^= w;
	}

	for(int i = 1; i <= n; ++i)
		++cnt[val[i]];

	cnt[0] = 0;
	for(int i = 1; i < 16; ++i) {
		ans += cnt[i] / 2;
		if(cnt[i] & 1) fin |= 1 << i;
	}

	for(int i = 0; i < upp; ++i) {
		int r = 0;
		for(int o = 0; o < 16; ++o)
			if(i >> o & 1)
				r ^= o;
		if(!r) legal[i] = true;
	}

	memset(f, 32, sizeof f), f[0] = 0;
	for(int i = 1; i <= fin; ++i) {
		if((fin | i & fin) != fin || !legal[i]) continue;
		f[i] = bitcnt(i) - 1;
		for(int x = i; x; x = x - 1 & i) {
			int y = i ^ x;
			if(legal[x] && legal[y])
				f[i] = min(f[i], f[x] + f[y]);
		}
	}

	ans += f[fin];
	printf("%d\n", ans);
	return 0;
}