def dfs(graph, start):

    stack = [(start, 0)]

    visited = set()

    li = [0] * N

    while stack:

        d = stack.pop()

        li[d[0] - 1] = d[1] % 2

        for node, w in graph[d[0]]:

            if node not in visited:

                visited.add(node)

                stack.append((node, d[1] + w))

    return li





N = int(eval(input()))

g = {i: []for i in range(1, N + 1)}

for i in range(N - 1):

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

    w %= 2

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

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

for c in dfs(g, 1):

    print(c)
N=int(eval(input()))

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

for _ in range(N-1):

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

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

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

s=[(1,0)]

l=[-1]*N

while s:

  a,w=s.pop()

  l[a-1]=w%2

  for b,c in p[a]:

    if l[b-1]==-1:

      s.append((b,w+c))

for i in l:

	print(i)
def dfs(graph, start):
    stack = [(start, 0)]
    visited = set()
    li = [0] * N
    while stack:
        d = stack.pop()
        li[d[0] - 1] = d[1] % 2
        for node, w in graph[d[0]]:
            if node not in visited:
                visited.add(node)
                stack.append((node, d[1] + w))
    return li


N = int(eval(input()))
g = {i: [] for i in range(1, N + 1)}
for i in range(N - 1):
    u, v, w = list(map(int, input().split()))
    w %= 2
    g[u].append((v, w))
    g[v].append((u, w))
for c in dfs(g, 1):
    print(c)

N = int(eval(input()))
p = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    u, v, w = list(map(int, input().split()))
    p[u].append((v, w))
    p[v].append((u, w))
s = [(1, 0)]
l = [-1] * N
while s:
    a, w = s.pop()
    l[a - 1] = w % 2
    for b, c in p[a]:
        if l[b - 1] == -1:
            s.append((b, w + c))
for i in l:
    print(i)

-def dfs(graph, start): -    stack = [(start, 0)] -    visited = set() -    li = [0] * N -    while stack: -        d = stack.pop() -        li[d[0] - 1] = d[1] % 2 -        for node, w in graph[d[0]]: -            if node not in visited: -                visited.add(node) -                stack.append((node, d[1] + w)) -    return li - - -g = {i: [] for i in range(1, N + 1)} -for i in range(N - 1): +p = [[] for _ in range(N + 1)] +for _ in range(N - 1): -    w %= 2 -    g[u].append((v, w)) -    g[v].append((u, w)) -for c in dfs(g, 1): -    print(c) +    p[u].append((v, w)) +    p[v].append((u, w)) +s = [(1, 0)] +l = [-1] * N +while s: +    a, w = s.pop() +    l[a - 1] = w % 2 +    for b, c in p[a]: +        if l[b - 1] == -1: +            s.append((b, w + c)) +for i in l: +    print(i)