# -*- coding: utf-8 -*-

n = int(eval(input()))

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

for _ in range(n-1):

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

    u -= 1

    v -= 1

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

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



res = [-1]*n

res[0] = 0

q = [0]

while len(q)>0:

    u = q.pop(0)

    if len(edge[u])==0:

        continue



    for v,w in edge[u]:

        if res[v]!=-1:

            continue

        if w%2==0:

            res[v] = res[u]

        else:

            res[v] = (res[u]+1)%2

        q.append(v)



for r in res:

    print(r)

# -*- coding: utf-8 -*-

from collections import defaultdict

n = int(eval(input()))

e = defaultdict(lambda: [])



for _ in range(n-1):

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

    v -= 1

    u -= 1

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

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



col = [-1]*n

q = [0]

col[0] = 0

while len(q)>0:

    v = q.pop()

    for u,w in e[v]:

        if col[u]<0:

            if w%2==1:

                col[u] = (col[v]+1)%2

            else:

                col[u] = col[v]

            q.append(u)



print((*col))
# -*- coding: utf-8 -*-
n = int(eval(input()))
edge = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = list(map(int, input().split()))
    u -= 1
    v -= 1
    edge[u].append((v, w))
    edge[v].append((u, w))
res = [-1] * n
res[0] = 0
q = [0]
while len(q) > 0:
    u = q.pop(0)
    if len(edge[u]) == 0:
        continue
    for v, w in edge[u]:
        if res[v] != -1:
            continue
        if w % 2 == 0:
            res[v] = res[u]
        else:
            res[v] = (res[u] + 1) % 2
        q.append(v)
for r in res:
    print(r)

# -*- coding: utf-8 -*-
from collections import defaultdict

n = int(eval(input()))
e = defaultdict(lambda: [])
for _ in range(n - 1):
    v, u, w = list(map(int, input().split()))
    v -= 1
    u -= 1
    e[v].append((u, w))
    e[u].append((v, w))
col = [-1] * n
q = [0]
col[0] = 0
while len(q) > 0:
    v = q.pop()
    for u, w in e[v]:
        if col[u] < 0:
            if w % 2 == 1:
                col[u] = (col[v] + 1) % 2
            else:
                col[u] = col[v]
            q.append(u)
print((*col))

+from collections import defaultdict + -edge = [[] for _ in range(n)] +e = defaultdict(lambda: []) -    u, v, w = list(map(int, input().split())) +    v, u, w = list(map(int, input().split())) +    v -= 1 -    v -= 1 -    edge[u].append((v, w)) -    edge[v].append((u, w)) -res = [-1] * n -res[0] = 0 +    e[v].append((u, w)) +    e[u].append((v, w)) +col = [-1] * n +col[0] = 0 -    u = q.pop(0) -    if len(edge[u]) == 0: -        continue -    for v, w in edge[u]: -        if res[v] != -1: -            continue -        if w % 2 == 0: -            res[v] = res[u] -        else: -            res[v] = (res[u] + 1) % 2 -        q.append(v) -for r in res: -    print(r) +    v = q.pop() +    for u, w in e[v]: +        if col[u] < 0: +            if w % 2 == 1: +                col[u] = (col[v] + 1) % 2 +            else: +                col[u] = col[v] +            q.append(u) +print((*col))