//InTheNameOfGod
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define rep(i,j,k) for(int i=j;i<k;++i)
#define rrep(i,j,k) for(int i=j;i>=k;i--)
#define pb push_back
#define lb(i) i&(-i);
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int maxn =1e5+5;
int n,a[maxn],xr[maxn],dp[(1<<16)],cal[maxn],re;
bool ok[16];
vector<int> v;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>n;
    rep(i,1,n)
    {
        int x,y,w;
        cin>>x>>y>>w;
        xr[x]^=w;
        xr[y]^=w;
    }
    rep(i,0,n)
    {
        if(xr[i]==0)
        {
            re++;
        }
        else if(ok[xr[i]])
        {
            ok[xr[i]]=0;
            re++;
        }
        else
        {
            ok[xr[i]]=1;
        }
    }
    rep(i,1,16)if(ok[i])
    {
        v.pb(i);
        //cout<<v.back()<<' ';
    }
    //cout<<endl;
    int l=v.size();
    rep(i,1,(1<<l))
    {
        int j=0;
        while(!(i&(1<<j)))j++;
        cal[i]=cal[i^(1<<j)]^v[j];
    }
    rep(i,1,(1<<l))
    {
        dp[i]=1000;
        for(int sub=i;sub>0;sub=(sub-1)&i)if(cal[sub]==0)
        {
            dp[i]=min(dp[i],dp[i^sub]+1);
        }
    }
    re+=dp[(1<<l)-1];
    cout<<n-re;
    return 0;
}
