#include <cstdio>

#define min(a, b) (a) < (b)?(a):(b)

const int N = 1e5 + 7, M = 22;
int n, otp, state, w[N], corder[M], dp[(1<<15) + 7], XOR[(1<<15) + 7];

inline void init(){
	for (register int i = 1;i < (1<<15);i ++)dp[i] = dp[i>>1] + (i&1);
	for (register int i = 1;i < (1<<15);i ++)dp[i] --;
	for (register int i = 1;i < (1<<15);i ++)
		for (register int j = 0;j < 15;j ++)
			if ((i>>j)&1)XOR[i] ^= (j + 1);
	for (register int i = 1;i < (1<<15);i ++)
		if (!XOR[i])
			for (register int j = i&(i - 1);j;j = i&(j - 1))
				if (!XOR[j])dp[i] = min(dp[i], dp[i^j] + dp[j]);
	scanf("%d", &n);
	for (register int i = 1, x, y, z;i < n;i ++){
		scanf("%d %d %d", &x, &y, &z);
		w[x + 1] ^= z, w[y + 1] ^= z;
	}
}

int main(){
	init();
	for (register int i = 1;i <= n;i ++)corder[w[i]] ++;
	for (register int i = 1;i <= 15;i ++){
		otp += (corder[i]>>1);
		state |= ((corder[i]&1)<<(i - 1));
	}
	return !printf("%d", otp + dp[state]);
}