N=int(input())
G=[[] for _ in [0]*(N+1)]
for _ in [0]*(N-1):
    u,v,w=map(int,input().split())
    G[u].append((v,w))
    G[v].append((u,w))

c=[0]*(N+1)
stack=[1]
c[1]=1
while stack:
    r=stack.pop()
    for nr,nw in G[r]:
        if c[nr]==0:
            stack.append(nr)
            if nw%2:
                c[nr]=-c[r]
            else:
                c[nr]=c[r]
for i in c[1:]:
    print((i+1)//2) N=int(input()) N int(input()) int input() input [] for _ in [0]*(N+1) for _ in [0]*(N+1) _ [0]*(N+1) [0] 0 N+1 N 1 for _ in [0]*(N+1) [] G=[[] for _ in [0]*(N+1)] G [[] for _ in [0]*(N+1)] for _ in [0]*(N-1):
    u,v,w=map(int,input().split())
    G[u].append((v,w))
    G[v].append((u,w)) _ [0]*(N-1) [0] 0 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 G[u].append((v,w)) [u].append [u] G u append (v,w) v w G[v].append((u,w)) [v].append [v] G v append (u,w) u w c=[0]*(N+1) c [0]*(N+1) [0] 0 N+1 N 1 stack=[1] stack [1] 1 c[1]=1 c[1] c 1 1 while stack:
    r=stack.pop()
    for nr,nw in G[r]:
        if c[nr]==0:
            stack.append(nr)
            if nw%2:
                c[nr]=-c[r]
            else:
                c[nr]=c[r] stack r=stack.pop() r stack.pop() stack.pop stack pop for nr,nw in G[r]:
        if c[nr]==0:
            stack.append(nr)
            if nw%2:
                c[nr]=-c[r]
            else:
                c[nr]=c[r] nr nw G[r] G r if c[nr]==0:
            stack.append(nr)
            if nw%2:
                c[nr]=-c[r]
            else:
                c[nr]=c[r] c[nr]==0 c[nr] c nr 0 stack.append(nr) stack.append stack append nr if nw%2:
                c[nr]=-c[r]
            else:
                c[nr]=c[r] nw%2 nw 2 c[nr]=-c[r] c[nr] c nr -c[r] c[r] c r c[nr]=c[r] c[nr] c nr c[r] c r for i in c[1:]:
    print((i+1)//2) i c[1:] c 1: 1 print((i+1)//2) print (i+1)//2 i+1 i 1 2 w=map(int,input().split()) map(int,input().split()) w r=stack.pop() stack.pop() r u,v,w=map(int,input().split()) map(int,input().split()) u c=[0]*(N+1) [0]*(N+1) c N=int(input()) int(input()) N stack=[1] [1] stack G=[[] for _ in [0]*(N+1)] [[] for _ in [0]*(N+1)] G v,w=map(int,input().split()) map(int,input().split()) v
N=int(input())
G=[[] for _ in [0]*(N+1)]
for _ in [0]*(N-1):
    u,v,w=map(int,input().split())
    G[u].append((v,w))
    G[v].append((u,w))

c=[0]*(N+1)
stack=[1]
c[1]=1
while stack:
    r=stack.pop()
    for nr,nw in G[r]:
        if c[nr]==0:
            stack.append(nr)
            if nw%2:
                c[nr]=-c[r]
            else:
                c[nr]=c[r]
for i in c[1:]:
    print((i+1)//2)