using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }


    Scanner cin;


    int N;
    int[] X;
    int[] Y;
    int[] A;
    List<Tuple<int, int>>[] es;

    const int MAX = (1 << 16);
    const int B = 16;
    int[] dp = new int[MAX];
    int[] dec = new int[MAX];
    int[,] next = new int[MAX, 16];
    bool[,] nextok = new bool[MAX, 16];

    int ans = 0;
    

    void calc()
    {

        cin = new Scanner();

        for (int i = 0; i < MAX; i++)
        {
            dp[i] = 0;
            //3-set
            for (int j = 0; j < B; j++)
            {
                if (((i >> j) & 1) == 0) continue;
                for (int k = j + 1; k < B; k++)
                {
                    if (((i >> k) & 1) == 0) continue;
                    int l = j ^ k;
                    if (((i >> l) & 1) == 0) continue;
                    if (l <= k) continue;
                    dp[i] = Math.Max(dp[i], dp[i - (1 << j) - (1 << k) - (1 << l)] + 1);
                }
            }
            //4-set
            for (int j = 0; j < B; j++)
            {
                if (((i >> j) & 1) == 0) continue;
                for (int k = j + 1; k < B; k++)
                {
                    if (((i >> k) & 1) == 0) continue;
                    for (int l = k + 1; l < B; l++)
                    {
                        if (((i >> l) & 1) == 0) continue;

                        int m = (j ^ k ^ l);
                        if (((i >> m) & 1) == 0) continue;
                        if (m <= l) continue;
                        dp[i] = Math.Max(dp[i], dp[i - (1 << j) - (1 << k) - (1 << l) - (1 << m)] + 1);
                    }
                }
            }


            //5-set
            for (int j = 0; j < B; j++)
            {
                if (((i >> j) & 1) == 0) continue;
                for (int k = j + 1; k < B; k++)
                {
                    if (((i >> k) & 1) == 0) continue;
                    for (int l = k + 1; l < B; l++)
                    {
                        if (((i >> l) & 1) == 0) continue;
                        for (int n = l + 1; n < B; n++)
                        {
                            if (((i >> n) & 1) == 0) continue;

                            int m = (j ^ k ^ l ^ n);
                            if (((i >> m) & 1) == 0) continue;
                            if (m <= n) continue;
                            dp[i] = Math.Max(dp[i], dp[i - (1 << j) - (1 << k) - (1 << l) - (1 << m) - (1 << n)] + 1);
                        }
                    }
                }
            }
        }

        N = cin.nextInt();
        X = new int[N];
        Y = new int[N];
        A = new int[N];
        int[] P = new int[N];
        es = new List<Tuple<int, int>>[N];

        for (int i = 0; i < N; i++)
        {
            es[i] = new List<Tuple<int, int>>();
        }
        
        for (int i = 0; i < N - 1; i++)
        {
            X[i] = cin.nextInt();
            Y[i] = cin.nextInt();
            A[i] = cin.nextInt();
            P[X[i]] ^= A[i];
            P[Y[i]] ^= A[i];
        }

        int[] sum = new int[B];
        for (int i = 0; i < N; i++)
        {
            sum[P[i]]++;
        }

        int ans = 0;
        int flag = 0;
        for (int i = 1; i < B; i++)
        {
            ans += (sum[i] + 1) / 2;
            if (sum[i] % 2 == 1) flag |= (1 << i);
        }
        
        ans -= dp[flag];
        Console.WriteLine(ans);
    }

    int bitCount(long x)
    {
        x = (x & 0x5555555555555555) + (x >> 1 & 0x5555555555555555);
        x = (x & 0x3333333333333333) + (x >> 2 & 0x3333333333333333);
        x = (x & 0x0f0f0f0f0f0f0f0f) + (x >> 4 & 0x0f0f0f0f0f0f0f0f);
        x = (x & 0x00ff00ff00ff00ff) + (x >> 8 & 0x00ff00ff00ff00ff);
        x = (x & 0x0000ffff0000ffff) + (x >> 16 & 0x0000ffff0000ffff);
        return (int)((x & 0x00000000ffffffff) + (x >> 32 & 0x00000000ffffffff));
    }


}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 29536