/**
 *    author:  tourist
 *    created: 03.02.2018 17:31:24       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  vector<int> val(n);
  for (int i = 0; i < n - 1; i++) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    val[x] ^= z;
    val[y] ^= z;
  }
  vector<int> cnt(16);
  for (int i = 0; i < n; i++) {
    cnt[val[i]]++;
  }
  int ans = 0;
  for (int i = 1; i < 16; i++) {
    ans += cnt[i] / 2;
    cnt[i] %= 2;
  }
  int mask = 0;
  for (int i = 1; i < 16; i++) {
    if (cnt[i] == 1) {
      mask |= (1 << i);
    }
  }
  vector<int> good(1 << 16);
  for (int t = 0; t < (1 << 16); t++) {
    int x = 0;
    for (int i = 0; i < 16; i++) {
      if (t & (1 << i)) {
        x ^= i;
      }
    }
    good[t] = (x == 0);
  }
  vector<int> dp(1 << 16, 0);
  for (int t = 0; t < (1 << 16); t++) {
    if (t & 1) {
      continue;
    }
    int u = t;
    while (u > 0) {
      if (good[u]) {
        dp[t] = max(dp[t], dp[t ^ u] + 1);
      }
      u = (u - 1) & t;
    }
  }
  printf("%d\n", ans + __builtin_popcount(mask) - dp[mask]);
  return 0;
}
