n=int(input())
e=[[[],[]] for i in range(n)]
for i in range(n-1):
  u,v,w=map(int,input().split())
  u-=1
  v-=1
  w%=2
  e[u][w].append(v)
  e[v][w].append(u)

ans=[None for i in range(n)]
ans[0]=0
s=[0]
while s:
  ns=[]
  for i in s:
    for j in e[i][0]:
      if ans[j]!=None:
        continue
      ns.append(j)
      ans[j]=ans[i]
    for j in e[i][1]:
      if ans[j]!=None:
        continue
      ns.append(j)
      ans[j]=1-ans[i]
  s=ns
print("\n".join(map(str,ans))) n=int(input()) n int(input()) int input() input [[],[]] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [[],[]] [] [] e=[[[],[]] for i in range(n)] e [[[],[]] for i in range(n)] for i in range(n-1):
  u,v,w=map(int,input().split())
  u-=1
  v-=1
  w%=2
  e[u][w].append(v)
  e[v][w].append(u) i 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 u-=1 u 1 v-=1 v 1 w%=2 w 2 e[u][w].append(v) [w].append [w] [u] e u w append v e[v][w].append(u) [w].append [w] [v] e v w append u None for i in range(n) for i in range(n) i range(n) range n for i in range(n) None ans=[None for i in range(n)] ans [None for i in range(n)] ans[0]=0 ans[0] ans 0 0 s=[0] s [0] 0 while s:
  ns=[]
  for i in s:
    for j in e[i][0]:
      if ans[j]!=None:
        continue
      ns.append(j)
      ans[j]=ans[i]
    for j in e[i][1]:
      if ans[j]!=None:
        continue
      ns.append(j)
      ans[j]=1-ans[i]
  s=ns s ns=[] ns [] for i in s:
    for j in e[i][0]:
      if ans[j]!=None:
        continue
      ns.append(j)
      ans[j]=ans[i]
    for j in e[i][1]:
      if ans[j]!=None:
        continue
      ns.append(j)
      ans[j]=1-ans[i]
   i s for j in e[i][0]:
      if ans[j]!=None:
        continue
      ns.append(j)
      ans[j]=ans[i]
     j e[i][0] [i] e i 0 if ans[j]!=None:
        continue
       ans[j]!=None ans[j] ans j None continue ns.append(j) ns.append ns append j ans[j]=ans[i] ans[j] ans j ans[i] ans i for j in e[i][1]:
      if ans[j]!=None:
        continue
      ns.append(j)
      ans[j]=1-ans[i]
   j e[i][1] [i] e i 1 if ans[j]!=None:
        continue
       ans[j]!=None ans[j] ans j None continue ns.append(j) ns.append ns append j ans[j]=1-ans[i] ans[j] ans j 1-ans[i] 1 ans[i] ans i s=ns s ns print("\n".join(map(str,ans))) print "\n".join(map(str,ans)) "\n".join "\n" join map(str,ans) map str ans s=ns ns s u,v,w=map(int,input().split()) map(int,input().split()) u ans=[None for i in range(n)] [None for i in range(n)] ans e=[[[],[]] for i in range(n)] [[[],[]] for i in range(n)] e u-=1 1 u w%=2 2 w v,w=map(int,input().split()) map(int,input().split()) v w=map(int,input().split()) map(int,input().split()) w s=[0] [0] s v-=1 1 v n=int(input()) int(input()) n ns=[] [] ns
n=int(input())
e=[[[],[]] for i in range(n)]
for i in range(n-1):
  u,v,w=map(int,input().split())
  u-=1
  v-=1
  w%=2
  e[u][w].append(v)
  e[v][w].append(u)

ans=[None for i in range(n)]
ans[0]=0
s=[0]
while s:
  ns=[]
  for i in s:
    for j in e[i][0]:
      if ans[j]!=None:
        continue
      ns.append(j)
      ans[j]=ans[i]
    for j in e[i][1]:
      if ans[j]!=None:
        continue
      ns.append(j)
      ans[j]=1-ans[i]
  s=ns
print("\n".join(map(str,ans)))