from collections import deque

n = int(eval(input()))



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

color1 = [-1] * (n+1)

color1[1] = 0

color2 = [-1] * (n+1)

color2[1] = 1

for _ in range(n-1):

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

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

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



q = deque([1])

visited = {1}

while len(q) > 0:

    now = q.popleft()

    visited.add(now)

    for v, w in tree[now]:

        if v in visited:

            pass

        else:

            q.append(v)

            if w % 2 == 0:

                color1[v] = color1[now]

                color2[v] = color2[now]

            else:

                color1[v] = int(not color1[now])

                color2[v] = int(not color2[now])



print(("\n".join(tuple(map(str, color1[1:])))))











n = int(eval(input()))



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



for _ in range(n-1):

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

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

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



color = [-1] * (n+1)

color[1] = 0

stack = [1]



while stack:

    node = stack.pop()

    for vertex, weight in tree[node]:

        if color[vertex] != -1:

            continue

        color[vertex] = (color[node] + weight) % 2

        stack.append(vertex)



print(("\n".join(map(str, color[1:]))))







from collections import deque

n = int(eval(input()))
tree = [[] for _ in range(n + 1)]
color1 = [-1] * (n + 1)
color1[1] = 0
color2 = [-1] * (n + 1)
color2[1] = 1
for _ in range(n - 1):
    u, v, w = list(map(int, input().split()))
    tree[u].append((v, w))
    tree[v].append((u, w))
q = deque([1])
visited = {1}
while len(q) > 0:
    now = q.popleft()
    visited.add(now)
    for v, w in tree[now]:
        if v in visited:
            pass
        else:
            q.append(v)
            if w % 2 == 0:
                color1[v] = color1[now]
                color2[v] = color2[now]
            else:
                color1[v] = int(not color1[now])
                color2[v] = int(not color2[now])
print(("\n".join(tuple(map(str, color1[1:])))))

n = int(eval(input()))
tree = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    u, v, w = list(map(int, input().split()))
    tree[u].append([v, w])
    tree[v].append([u, w])
color = [-1] * (n + 1)
color[1] = 0
stack = [1]
while stack:
    node = stack.pop()
    for vertex, weight in tree[node]:
        if color[vertex] != -1:
            continue
        color[vertex] = (color[node] + weight) % 2
        stack.append(vertex)
print(("\n".join(map(str, color[1:]))))

-from collections import deque - -color1 = [-1] * (n + 1) -color1[1] = 0 -color2 = [-1] * (n + 1) -color2[1] = 1 -    tree[u].append((v, w)) -    tree[v].append((u, w)) -q = deque([1]) -visited = {1} -while len(q) > 0: -    now = q.popleft() -    visited.add(now) -    for v, w in tree[now]: -        if v in visited: -            pass -        else: -            q.append(v) -            if w % 2 == 0: -                color1[v] = color1[now] -                color2[v] = color2[now] -            else: -                color1[v] = int(not color1[now]) -                color2[v] = int(not color2[now]) -print(("\n".join(tuple(map(str, color1[1:]))))) +    tree[u].append([v, w]) +    tree[v].append([u, w]) +color = [-1] * (n + 1) +color[1] = 0 +stack = [1] +while stack: +    node = stack.pop() +    for vertex, weight in tree[node]: +        if color[vertex] != -1: +            continue +        color[vertex] = (color[node] + weight) % 2 +        stack.append(vertex) +print(("\n".join(map(str, color[1:]))))