from collections import deque
n=int(input())
uv=[[] for _ in range(n+1)]
for i in range(n-1):
    u,v,w=map(int,input().split())
    uv[u].append([v,w])
    uv[v].append([u,w])
stack=[1]
ans=[-1]*(n+1)
ans[1]=0
while stack:
    x=stack.pop()
    for j in uv[x]:
        if ans[j[0]]==-1:
            if j[1]%2==0:
                ans[j[0]]=ans[x]
            else:
                ans[j[0]]=(ans[x]+1)%2
            stack.append(j[0])

for k in range(1,n+1):
    print(ans[k]) from collections import deque n=int(input()) n int(input()) int input() input [] for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) [] uv=[[] for _ in range(n+1)] uv [[] for _ in range(n+1)] for i in range(n-1):
    u,v,w=map(int,input().split())
    uv[u].append([v,w])
    uv[v].append([u,w]) 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 uv[u].append([v,w]) [u].append [u] uv u append [v,w] v w uv[v].append([u,w]) [v].append [v] uv v append [u,w] u w stack=[1] stack [1] 1 ans=[-1]*(n+1) ans [-1]*(n+1) [-1] -1 n+1 n 1 ans[1]=0 ans[1] ans 1 0 while stack:
    x=stack.pop()
    for j in uv[x]:
        if ans[j[0]]==-1:
            if j[1]%2==0:
                ans[j[0]]=ans[x]
            else:
                ans[j[0]]=(ans[x]+1)%2
            stack.append(j[0]) stack x=stack.pop() x stack.pop() stack.pop stack pop for j in uv[x]:
        if ans[j[0]]==-1:
            if j[1]%2==0:
                ans[j[0]]=ans[x]
            else:
                ans[j[0]]=(ans[x]+1)%2
            stack.append(j[0]) j uv[x] uv x if ans[j[0]]==-1:
            if j[1]%2==0:
                ans[j[0]]=ans[x]
            else:
                ans[j[0]]=(ans[x]+1)%2
            stack.append(j[0]) ans[j[0]]==-1 ans[j[0]] ans j[0] j 0 -1 if j[1]%2==0:
                ans[j[0]]=ans[x]
            else:
                ans[j[0]]=(ans[x]+1)%2
             j[1]%2==0 j[1]%2 j[1] j 1 2 0 ans[j[0]]=ans[x] ans[j[0]] ans j[0] j 0 ans[x] ans x ans[j[0]]=(ans[x]+1)%2 ans[j[0]] ans j[0] j 0 (ans[x]+1)%2 ans[x]+1 ans[x] ans x 1 2 stack.append(j[0]) stack.append stack append j[0] j 0 for k in range(1,n+1):
    print(ans[k]) k range(1,n+1) range 1 n+1 n 1 print(ans[k]) print ans[k] ans k w=map(int,input().split()) map(int,input().split()) w uv=[[] for _ in range(n+1)] [[] for _ in range(n+1)] uv v,w=map(int,input().split()) map(int,input().split()) v ans=[-1]*(n+1) [-1]*(n+1) ans n=int(input()) int(input()) n stack=[1] [1] stack x=stack.pop() stack.pop() x u,v,w=map(int,input().split()) map(int,input().split()) u
from collections import deque
n=int(input())
uv=[[] for _ in range(n+1)]
for i in range(n-1):
    u,v,w=map(int,input().split())
    uv[u].append([v,w])
    uv[v].append([u,w])
stack=[1]
ans=[-1]*(n+1)
ans[1]=0
while stack:
    x=stack.pop()
    for j in uv[x]:
        if ans[j[0]]==-1:
            if j[1]%2==0:
                ans[j[0]]=ans[x]
            else:
                ans[j[0]]=(ans[x]+1)%2
            stack.append(j[0])

for k in range(1,n+1):
    print(ans[k])
