#include <bits/stdc++.h>
using namespace std;
int n;
int r[1010];
struct node{
int s,d;
bool c;
} q[1010];
int main(){
freopen("rotation.in","r",stdin);
freopen("rotation.out","w",stdout);
scanf("%d",&n);
for (int i=1;i<n;i++) scanf("%d %d %d",&q[i].s,&q[i].d,&q[i].c);
r[1]=1;
for (int i=1;i<n;i++){
for (int j=1;j<n;j++){
if (!r[q[j].s]) continue;
if (q[j].c) r[q[j].d]=r[q[j].s]*(-1);
else r[q[j].d]=r[q[j].s];
}
}
if (r[n]==1) printf("0");
else printf("1");
return 0;
}