#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define mp make_pair
using namespace std;
ifstream fin("rotation.in");
ofstream fout("rotation.out");
auto mread = [](){int x;fin >> x;return x;};
const int N = 1005;
int n = mread(), d[N];
vector<pair<int, int> > v[N];
signed main(){
for(int i = 1, x, y, z; i < n; i ++){
x = mread(), y = mread(), z = mread();
v[x].push_back(mp(y, z));
}
queue<int> q;
q.push(1);
while(q.size()){
int x = q.front();
q.pop();
for(auto t : v[x]){
int y = t.fi, w = t.se;
d[y] = d[x] ^ 1;
q.push(y);
}
}
fout << d[n];
return 0;
}