1 #include <bits/stdc++.h>
2 using namespace std;
3 struct edge
4 {
5 int v, w, nxt;
6 }e[2005];
7 int n, fst[1005];
8 bool dis[1005], vis[1005];
9
10 void addedge(int i, int u, int v, int w)
11 {
12 e[i] = (edge){v, w, fst[u]}, fst[u] = i;
13 }
14
15 void DFS(int u)
16 {
17 for(int i = fst[u]; i; i = e[i].nxt)
18 if(!vis[e[i].v])
19 {
20 dis[e[i].v] = dis[u] ^ e[i].w;
21 vis[e[i].v] = true;
22 DFS(e[i].v);
23 }
24 }
25
26 int main()
27 {
28 int u, v, w;
29 cin >> n;
30 for(int i = 1; i < n; i++)
31 {
32 cin >> u >> v >> w;
33 addedge(i, u, v, w);
34 }
35 DFS(1);
36 cout << dis[n] << endl;
37 return 0;
38 }