import sys

sys.setrecursionlimit(10**8)



N = int(input())

edge = [[] for _ in range(N+1)]

for i in range(N-1):

  u,v,w = map(int, input().split())

  edge[u].append([v,w%2])

  edge[v].append([u,w%2])

color = [0]*(N+1)

visited = [False]*(N+1)

def dfs(u):

  for v,w in edge[u]:

    if visited[v]==False:

      #print(v)

      visited[v]=True

      color[v]=color[u]^w

      dfs(v)

  return 0

visited[1]=True

dfs(1)

ans = color[1:]

print(*ans,sep='\n')

import sys

sys.setrecursionlimit(10**8)



N = int(input())

edge = [[] for _ in range(N)]



for _ in range(N-1):

  u,v,w = map(int, input().split())

  w %= 2

  v -= 1

  u -= 1

  edge[u].append((w,v))

  edge[v].append((w,u))



color = [-1]*N

#print(edge)

def dfs(s,col):

  #print(s,col)

  for w,v in edge[s]:

    if color[v]==-1:

      color[v] = col^w

      dfs(v,color[v])

  return



color[0] = 0

dfs(0,0)

ans = color



#print(ans)

print(*ans,sep='\n')

import sys

sys.setrecursionlimit(10**8)
N = int(input())
edge = [[] for _ in range(N + 1)]
for i in range(N - 1):
    u, v, w = map(int, input().split())
    edge[u].append([v, w % 2])
    edge[v].append([u, w % 2])
color = [0] * (N + 1)
visited = [False] * (N + 1)


def dfs(u):
    for v, w in edge[u]:
        if visited[v] == False:
            # print(v)
            visited[v] = True
            color[v] = color[u] ^ w
            dfs(v)
    return 0


visited[1] = True
dfs(1)
ans = color[1:]
print(*ans, sep="\n")

import sys

sys.setrecursionlimit(10**8)
N = int(input())
edge = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    w %= 2
    v -= 1
    u -= 1
    edge[u].append((w, v))
    edge[v].append((w, u))
color = [-1] * N
# print(edge)
def dfs(s, col):
    # print(s,col)
    for w, v in edge[s]:
        if color[v] == -1:
            color[v] = col ^ w
            dfs(v, color[v])
    return


color[0] = 0
dfs(0, 0)
ans = color
# print(ans)
print(*ans, sep="\n")

-edge = [[] for _ in range(N + 1)] -for i in range(N - 1): +edge = [[] for _ in range(N)] +for _ in range(N - 1): -    edge[u].append([v, w % 2]) -    edge[v].append([u, w % 2]) -color = [0] * (N + 1) -visited = [False] * (N + 1) +    w %= 2 +    v -= 1 +    u -= 1 +    edge[u].append((w, v)) +    edge[v].append((w, u)) +color = [-1] * N +# print(edge) +def dfs(s, col): +    # print(s,col) +    for w, v in edge[s]: +        if color[v] == -1: +            color[v] = col ^ w +            dfs(v, color[v]) +    return -def dfs(u): -    for v, w in edge[u]: -        if visited[v] == False: -            # print(v) -            visited[v] = True -            color[v] = color[u] ^ w -            dfs(v) -    return 0 - - -visited[1] = True -dfs(1) -ans = color[1:] +color[0] = 0 +dfs(0, 0) +ans = color +# print(ans)