#include <stdio.h>

int N,X[100100],C[1<<16],D[1<<16];

int main()
{
	scanf ("%d",&N);
	for (int i=1;i<N;i++){
		int x,y,c; scanf ("%d %d %d",&x,&y,&c);
		X[x] ^= c;
		X[y] ^= c;
	}

	for (int i=0;i<N;i++) C[1<<X[i]]++;
	C[1] = 0;

	int ans = 16;
	for (int i=1;i<16;i++){
		int &c = C[1<<i];
		ans += c / 2;
		c = c % 2 * i;
	}

	for (int i=1;i<(1<<16);i++){
		int x = i & (-i);
		C[i] = C[i-x] ^ C[x];

		D[i] = -99999;
		for (int j=i;j;j=(j-1)&i) if (C[j] == 0){
			if (D[i] < D[i-j] + 1)
				D[i] = D[i-j] + 1;
		}
	}
	ans -= D[(1<<16)-1];

	printf ("%d\n",ans);

	return 0;
}