import sys
from collections import deque
input=sys.stdin.readline
N=int(input())
tree=[[] for _ in range(N)]
for _ in range(N-1):
  u,v,w=map(int,input().split())
  tree[u-1].append((v-1,w))
  tree[v-1].append((u-1,w))
ans=[-1]*N
ans[0]=0
d=deque([0])
while d:
  p=deque.popleft(d)
  color=ans[p]
  for v,w in tree[p]:
    if ans[v]==-1:
      deque.append(d,v)
      ans[v]=color^(w%2)
print(*ans,sep='\n') import sys sys from collections import deque input=sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline N=int(input()) N int(input()) int input() input [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] tree=[[] for _ in range(N)] tree [[] for _ in range(N)] for _ in range(N-1):
  u,v,w=map(int,input().split())
  tree[u-1].append((v-1,w))
  tree[v-1].append((u-1,w)) _ range(N-1) range N-1 N 1 u,v,w=map(int,input().split()) u map(int,input().split()) map int input().split() ().split () input split v w tree[u-1].append((v-1,w)) [u-1].append [u-1] tree u-1 u 1 append (v-1,w) v-1 v 1 w tree[v-1].append((u-1,w)) [v-1].append [v-1] tree v-1 v 1 append (u-1,w) u-1 u 1 w ans=[-1]*N ans [-1]*N [-1] -1 N ans[0]=0 ans[0] ans 0 0 d=deque([0]) d deque([0]) deque [0] 0 while d:
  p=deque.popleft(d)
  color=ans[p]
  for v,w in tree[p]:
    if ans[v]==-1:
      deque.append(d,v)
      ans[v]=color^(w%2) d p=deque.popleft(d) p deque.popleft(d) deque.popleft deque popleft d color=ans[p] color ans[p] ans p for v,w in tree[p]:
    if ans[v]==-1:
      deque.append(d,v)
      ans[v]=color^(w%2) v w tree[p] tree p if ans[v]==-1:
      deque.append(d,v)
      ans[v]=color^(w%2) ans[v]==-1 ans[v] ans v -1 deque.append(d,v) deque.append deque append d v ans[v]=color^(w%2) ans[v] ans v color^(w%2) color w%2 w 2 print(*ans,sep='\n') print *ans ans sep='\n' sep '\n' w=map(int,input().split()) map(int,input().split()) w ans=[-1]*N [-1]*N ans color=ans[p] ans[p] color p=deque.popleft(d) deque.popleft(d) p d=deque([0]) deque([0]) d tree=[[] for _ in range(N)] [[] for _ in range(N)] tree u,v,w=map(int,input().split()) map(int,input().split()) u input=sys.stdin.readline sys.stdin.readline input v,w=map(int,input().split()) map(int,input().split()) v N=int(input()) int(input()) N
import sys
from collections import deque
input=sys.stdin.readline
N=int(input())
tree=[[] for _ in range(N)]
for _ in range(N-1):
  u,v,w=map(int,input().split())
  tree[u-1].append((v-1,w))
  tree[v-1].append((u-1,w))
ans=[-1]*N
ans[0]=0
d=deque([0])
while d:
  p=deque.popleft(d)
  color=ans[p]
  for v,w in tree[p]:
    if ans[v]==-1:
      deque.append(d,v)
      ans[v]=color^(w%2)
print(*ans,sep='\n')