1 const maxn=1500;
2 var f:array[0..maxn,0..maxn] of longint;
3 g:array[0..maxn] of longint;
4 v:array[0..maxn] of boolean;
5 i,n,x,y,z:longint;
6 procedure dfs(x:longint);
7 var i:longint;
8 begin
9 v[x]:=true;
10 for i:=1 to n do
11 if (f[x,i]<>0) and (not(v[i])) then
12 begin
13 if f[x,i]=1 then g[i]:=g[x] else g[i]:=g[x] xor 1;
14 dfs(i);
15 end;
16 end;
17 begin
18 assign(input,‘input.txt‘);assign(output,‘output.txt‘);
19 reset(input);rewrite(output);
20 readln(n);
21 for i:=1 to n-1 do
22 begin
23 readln(x,y,z);inc(z);
24 f[x,y]:=z;
25 f[y,x]:=z;
26 end;
27 g[1]:=0;
28 dfs(1);
29 writeln(g[n]);
30 close(input);close(output);
31 end.