import sys



sys.setrecursionlimit(10 ** 7)





def dfs(v):

    for u, w in e[v]:

        if c[u] != -1:

            continue

        c[u] = (c[v] + w) % 2

        dfs(u)





n = int(input())

e = tuple(set() for _ in range(n))

for _ in range(n - 1):

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

    u -= 1

    v -= 1

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

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



c = [-1] * n

c[0] = 0



dfs(0)



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

from collections import deque



n = int(input())

g = tuple(set() for _ in range(n))

for _ in range(n - 1):

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

    u -= 1

    v -= 1

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

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



d = [-1] * n

d[0] = 0



q = deque()

q.append(0)



while q:

    v = q.popleft()

    for u, w in g[v]:

        if d[u] != -1:

            continue

        d[u] = (d[v] + w) % 2

        q.append(u)



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

import sys

sys.setrecursionlimit(10**7)


def dfs(v):
    for u, w in e[v]:
        if c[u] != -1:
            continue
        c[u] = (c[v] + w) % 2
        dfs(u)


n = int(input())
e = tuple(set() for _ in range(n))
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    e[u].add((v, w))
    e[v].add((u, w))
c = [-1] * n
c[0] = 0
dfs(0)
print(*c, sep="\n")

from collections import deque

n = int(input())
g = tuple(set() for _ in range(n))
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    g[u].add((v, w))
    g[v].add((u, w))
d = [-1] * n
d[0] = 0
q = deque()
q.append(0)
while q:
    v = q.popleft()
    for u, w in g[v]:
        if d[u] != -1:
            continue
        d[u] = (d[v] + w) % 2
        q.append(u)
print(*d, sep="\n")

-import sys - -sys.setrecursionlimit(10**7) - - -def dfs(v): -    for u, w in e[v]: -        if c[u] != -1: -            continue -        c[u] = (c[v] + w) % 2 -        dfs(u) - +from collections import deque -e = tuple(set() for _ in range(n)) +g = tuple(set() for _ in range(n)) -    e[u].add((v, w)) -    e[v].add((u, w)) -c = [-1] * n -c[0] = 0 -dfs(0) -print(*c, sep="\n") +    g[u].add((v, w)) +    g[v].add((u, w)) +d = [-1] * n +d[0] = 0 +q = deque() +q.append(0) +while q: +    v = q.popleft() +    for u, w in g[v]: +        if d[u] != -1: +            continue +        d[u] = (d[v] + w) % 2 +        q.append(u) +print(*d, sep="\n")