import sys

sys.setrecursionlimit(500*500)

n = int(eval(input()))

l = [list(map(int,input().split())) for _ in range(n-1)]

g = [[] for _ in range(n)]



for i in l:

    v = i[0]-1

    y = i[1]-1

    w = i[2]

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

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



seen = [0] + [-1] * (n-1)



def dfs(s):

    for k in g[s]:

        v,w = k[0],k[1]

        if seen[v]!=-1:continue

        seen[v] = seen[s]^(w%2)

        dfs(v)

        

dfs(0)



for i in seen:

    print(i)
n = int(eval(input()))



g = [[] for _ in range(n)]



for _ in range(n-1):

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

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

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



from collections import deque



que = deque()

seen = [0] + [-1]*(n-1)

que.append(0)

while que:

    s = que.popleft()

    for v,w in g[s]:

        if seen[v] != -1:continue

        seen[v] = seen[s]^(w%2)

        que.append(v)

for i in seen:

    print(i)
import sys

sys.setrecursionlimit(500 * 500)
n = int(eval(input()))
l = [list(map(int, input().split())) for _ in range(n - 1)]
g = [[] for _ in range(n)]
for i in l:
    v = i[0] - 1
    y = i[1] - 1
    w = i[2]
    g[v].append([y, w])
    g[y].append([v, w])
seen = [0] + [-1] * (n - 1)


def dfs(s):
    for k in g[s]:
        v, w = k[0], k[1]
        if seen[v] != -1:
            continue
        seen[v] = seen[s] ^ (w % 2)
        dfs(v)


dfs(0)
for i in seen:
    print(i)

n = int(eval(input()))
g = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = list(map(int, input().split()))
    g[u - 1].append((v - 1, w))
    g[v - 1].append((u - 1, w))
from collections import deque

que = deque()
seen = [0] + [-1] * (n - 1)
que.append(0)
while que:
    s = que.popleft()
    for v, w in g[s]:
        if seen[v] != -1:
            continue
        seen[v] = seen[s] ^ (w % 2)
        que.append(v)
for i in seen:
    print(i)

-import sys +n = int(eval(input())) +g = [[] for _ in range(n)] +for _ in range(n - 1): +    u, v, w = list(map(int, input().split())) +    g[u - 1].append((v - 1, w)) +    g[v - 1].append((u - 1, w)) +from collections import deque -sys.setrecursionlimit(500 * 500) -n = int(eval(input())) -l = [list(map(int, input().split())) for _ in range(n - 1)] -g = [[] for _ in range(n)] -for i in l: -    v = i[0] - 1 -    y = i[1] - 1 -    w = i[2] -    g[v].append([y, w]) -    g[y].append([v, w]) +que = deque() - - -def dfs(s): -    for k in g[s]: -        v, w = k[0], k[1] +que.append(0) +while que: +    s = que.popleft() +    for v, w in g[s]: -        dfs(v) - - -dfs(0) +        que.append(v)