n=int(input())
l=[[] for i in range(n)]
ans=[-1 for i in range(n)]
for i in range(n-1):
  u,v,w=[int(x) for x in input().rstrip().split()]
  l[u-1].append([v-1,w])
  l[v-1].append([u-1,w])

def bfs():
  ans[0]=0
  que=[0]
  while(que):
    now=que.pop(0)
    for i,j in l[now]:
      if ans[i]==-1:
        if j%2==0:
          ans[i]=ans[now]
        else:
          ans[i]=(ans[now]+1)%2
        que.append(i)

bfs()
for i in ans:print(i) 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) [] l=[[] for i in range(n)] l [[] for i in range(n)] -1 for i in range(n) for i in range(n) i range(n) range n for i in range(n) -1 ans=[-1 for i in range(n)] ans [-1 for i in range(n)] for i in range(n-1):
  u,v,w=[int(x) for x in input().rstrip().split()]
  l[u-1].append([v-1,w])
  l[v-1].append([u-1,w]) i range(n-1) range n-1 n 1 int(x) for x in input().rstrip().split() for x in input().rstrip().split() x input().rstrip().split() ().rstrip().split ().rstrip() ().rstrip () input rstrip split for x in input().rstrip().split() int(x) int x u,v,w=[int(x) for x in input().rstrip().split()] u [int(x) for x in input().rstrip().split()] v w l[u-1].append([v-1,w]) [u-1].append [u-1] l u-1 u 1 append [v-1,w] v-1 v 1 w l[v-1].append([u-1,w]) [v-1].append [v-1] l v-1 v 1 append [u-1,w] u-1 u 1 w def bfs():
  ans[0]=0
  que=[0]
  while(que):
    now=que.pop(0)
    for i,j in l[now]:
      if ans[i]==-1:
        if j%2==0:
          ans[i]=ans[now]
        else:
          ans[i]=(ans[now]+1)%2
        que.append(i) bfs ans[0]=0 ans[0] ans 0 0 que=[0] que [0] 0 while(que):
    now=que.pop(0)
    for i,j in l[now]:
      if ans[i]==-1:
        if j%2==0:
          ans[i]=ans[now]
        else:
          ans[i]=(ans[now]+1)%2
        que.append(i) que now=que.pop(0) now que.pop(0) que.pop que pop 0 for i,j in l[now]:
      if ans[i]==-1:
        if j%2==0:
          ans[i]=ans[now]
        else:
          ans[i]=(ans[now]+1)%2
        que.append(i) i j l[now] l now if ans[i]==-1:
        if j%2==0:
          ans[i]=ans[now]
        else:
          ans[i]=(ans[now]+1)%2
        que.append(i) ans[i]==-1 ans[i] ans i -1 if j%2==0:
          ans[i]=ans[now]
        else:
          ans[i]=(ans[now]+1)%2
         j%2==0 j%2 j 2 0 ans[i]=ans[now] ans[i] ans i ans[now] ans now ans[i]=(ans[now]+1)%2 ans[i] ans i (ans[now]+1)%2 ans[now]+1 ans[now] ans now 1 2 que.append(i) que.append que append i bfs() bfs for i in ans:print(i) i ans v,w=[int(x) for x in input().rstrip().split()] [int(x) for x in input().rstrip().split()] v u,v,w=[int(x) for x in input().rstrip().split()] [int(x) for x in input().rstrip().split()] u def bfs():
  ans[0]=0
  que=[0]
  while(que):
    now=que.pop(0)
    for i,j in l[now]:
      if ans[i]==-1:
        if j%2==0:
          ans[i]=ans[now]
        else:
          ans[i]=(ans[now]+1)%2
        que.append(i) def bfs():
  ans[0]=0
  que=[0]
  while(que):
    now=que.pop(0)
    for i,j in l[now]:
      if ans[i]==-1:
        if j%2==0:
          ans[i]=ans[now]
        else:
          ans[i]=(ans[now]+1)%2
        que.append(i) bfs n=int(input()) int(input()) n w=[int(x) for x in input().rstrip().split()] [int(x) for x in input().rstrip().split()] w l=[[] for i in range(n)] [[] for i in range(n)] l ans=[-1 for i in range(n)] [-1 for i in range(n)] ans
n=int(input())
l=[[] for i in range(n)]
ans=[-1 for i in range(n)]
for i in range(n-1):
  u,v,w=[int(x) for x in input().rstrip().split()]
  l[u-1].append([v-1,w])
  l[v-1].append([u-1,w])

def bfs():
  ans[0]=0
  que=[0]
  while(que):
    now=que.pop(0)
    for i,j in l[now]:
      if ans[i]==-1:
        if j%2==0:
          ans[i]=ans[now]
        else:
          ans[i]=(ans[now]+1)%2
        que.append(i)

bfs()
for i in ans:print(i)