#include<bits/stdc++.h>

using namespace std;

using int64 = long long;


int N, X[100000];
int dp[1 << 16];
int ok[1 << 16];

int rec(int bit) {
  if(~dp[bit]) return dp[bit];
  int ret = ok[bit];
  for(int i = bit; i > 0; i = (i - 1) & bit) {
    if(i == bit) continue;
    int other = i ^bit;
    ret = min(ret, rec(i) + rec(other));
  }
  return dp[bit] = ret;
}


int main() {
  cin >> N;
  for(int i = 1; i < N; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    X[x] ^= z;
    X[y] ^= z;
  }
  int bit = 0, ret = 0;
  for(int i = 0; i < N; i++) {
    if(X[i] == 0) continue;
    if(bit & (1 << X[i])) ++ret;
    bit ^= 1 << X[i];
  }
  memset(dp, -1, sizeof(dp));
  for(int i = 1; i < (1 << 16); i++) {
    ok[i] = ok[i & (i - 1)] + 1;
  }
  for(int i = 1; i < (1 << 16); i++) {
    int v = 0;
    for(int j = 0; j < 16; j++) {
      if((i >> j) & 1) v ^= j;
    }
    if(v == 0) --ok[i];
  }
  cout << ret + rec(bit) << endl;
}
