#include <bits/stdc++.h>
using namespace std;

int n, sum[100005], cnt[16], dp[1 << 15];

int main() {
	scanf("%d", &n);
	for (int i = 1, u, v, c; i < n; ++i) {
		scanf("%d%d%d", &u, &v, &c);
		sum[u] ^= c, sum[v] ^= c;
	}
	for (int i = 0; i < n; ++i) ++cnt[sum[i]];
	int ans = 0, buc = 0;
	for (int i = 1; i < 16; ++i) ans += cnt[i] >> 1, buc |= (cnt[i] & 1) << i - 1;
	for (int s = 1; s <= buc; ++s) {
		int t = 0;
		for (int i = 0; i < 15; ++i)
			if (s >> i & 1) ++dp[s], t ^= i + 1;
		dp[s] -= !t;
		for (int t = s - 1 & s; t; t = t - 1 & s)
			dp[s] = min(dp[s], dp[t] + dp[s ^ t]);
	}
	printf("%d\n", ans + dp[buc]);
}
