import queue

n = int(eval(input()))



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

color = [-1] * n

color[0] = 0



for _ in range(n-1):

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

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

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



q = queue.Queue()

q.put(0)



while not q.empty():

    i = q.get()

    c = color[i]

    for j, w in node[i]:

        if color[j] < 0:

            color[j] = c if w % 2 == 0 else (c + 1) % 2

            q.put(j)



for c in color:

    print(c)

    
from collections import deque

n = int(eval(input()))

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

for _ in range(n-1):

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

    u -= 1

    v -= 1

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

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



q = deque()

q.append(0)

color = [-1] * n

color[0] = 0



while q:

    v = q.popleft()

    for child, w in tree[v]:

        if color[child] < 0:

            color[child] = (color[v] + w) % 2

            q.append(child)



for i in color:

    print(i)

    
import queue

n = int(eval(input()))
node = [[] for _ in range(n)]
color = [-1] * n
color[0] = 0
for _ in range(n - 1):
    u, v, w = list(map(int, input().split()))
    node[u - 1].append((v - 1, w))
    node[v - 1].append((u - 1, w))
q = queue.Queue()
q.put(0)
while not q.empty():
    i = q.get()
    c = color[i]
    for j, w in node[i]:
        if color[j] < 0:
            color[j] = c if w % 2 == 0 else (c + 1) % 2
            q.put(j)
for c in color:
    print(c)

from collections import deque

n = int(eval(input()))
tree = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = list(map(int, input().split()))
    u -= 1
    v -= 1
    tree[u].append((v, w % 2))
    tree[v].append((u, w % 2))
q = deque()
q.append(0)
color = [-1] * n
color[0] = 0
while q:
    v = q.popleft()
    for child, w in tree[v]:
        if color[child] < 0:
            color[child] = (color[v] + w) % 2
            q.append(child)
for i in color:
    print(i)

-import queue +from collections import deque -node = [[] for _ in range(n)] +tree = [[] for _ in range(n)] +for _ in range(n - 1): +    u, v, w = list(map(int, input().split())) +    u -= 1 +    v -= 1 +    tree[u].append((v, w % 2)) +    tree[v].append((u, w % 2)) +q = deque() +q.append(0) -for _ in range(n - 1): -    u, v, w = list(map(int, input().split())) -    node[u - 1].append((v - 1, w)) -    node[v - 1].append((u - 1, w)) -q = queue.Queue() -q.put(0) -while not q.empty(): -    i = q.get() -    c = color[i] -    for j, w in node[i]: -        if color[j] < 0: -            color[j] = c if w % 2 == 0 else (c + 1) % 2 -            q.put(j) -for c in color: -    print(c) +while q: +    v = q.popleft() +    for child, w in tree[v]: +        if color[child] < 0: +            color[child] = (color[v] + w) % 2 +            q.append(child) +for i in color: +    print(i)