import sys

input = sys.stdin.readline

sys.setrecursionlimit(100000)



N = int(eval(input()))

G = [[] for _ in range(N)]

for _ in range(N - 1):

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

    u -= 1

    v -= 1

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

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



C = [-1] * N





def dfs(pos, color):

    C[pos] = color

    for e in G[pos]:

        if C[e[0]] != -1:

            continue

        # odd

        if e[1] & 1:

            c = 1 - color

            dfs(e[0], c)

        # even

        else:

            c = color

            dfs(e[0], c)





dfs(0, 0)

for c in C:

    print(c)

import sys

from collections import deque



input = sys.stdin.readline





def main():

    N = int(eval(input()))

    G = [[] for _ in range(N)]

    for i in range(N - 1):

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

        u -= 1

        v -= 1

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

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



    ans = [-1] * N

    ans[0] = 0

    stack = deque([(-1, 0)])

    while stack:

        p, u = stack.pop()

        for v, w in G[u]:

            if v == p:

                continue

            if w % 2 == 0:

                ans[v] = ans[u]

            else:

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

            stack.append((u, v))



    print(("\n".join(map(str, ans))))





if __name__ == "__main__":

    main()

import sys

input = sys.stdin.readline
sys.setrecursionlimit(100000)
N = int(eval(input()))
G = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v, w = list(map(int, input().split()))
    u -= 1
    v -= 1
    G[u].append((v, w))
    G[v].append((u, w))
C = [-1] * N


def dfs(pos, color):
    C[pos] = color
    for e in G[pos]:
        if C[e[0]] != -1:
            continue
        # odd
        if e[1] & 1:
            c = 1 - color
            dfs(e[0], c)
        # even
        else:
            c = color
            dfs(e[0], c)


dfs(0, 0)
for c in C:
    print(c)

import sys
from collections import deque

input = sys.stdin.readline


def main():
    N = int(eval(input()))
    G = [[] for _ in range(N)]
    for i in range(N - 1):
        u, v, w = list(map(int, input().split()))
        u -= 1
        v -= 1
        G[u].append((v, w))
        G[v].append((u, w))
    ans = [-1] * N
    ans[0] = 0
    stack = deque([(-1, 0)])
    while stack:
        p, u = stack.pop()
        for v, w in G[u]:
            if v == p:
                continue
            if w % 2 == 0:
                ans[v] = ans[u]
            else:
                ans[v] = (ans[u] + 1) % 2
            stack.append((u, v))
    print(("\n".join(map(str, ans))))


if __name__ == "__main__":
    main()

+from collections import deque -sys.setrecursionlimit(100000) -N = int(eval(input())) -G = [[] for _ in range(N)] -for _ in range(N - 1): -    u, v, w = list(map(int, input().split())) -    u -= 1 -    v -= 1 -    G[u].append((v, w)) -    G[v].append((u, w)) -C = [-1] * N -def dfs(pos, color): -    C[pos] = color -    for e in G[pos]: -        if C[e[0]] != -1: -            continue -        # odd -        if e[1] & 1: -            c = 1 - color -            dfs(e[0], c) -        # even -        else: -            c = color -            dfs(e[0], c) +def main(): +    N = int(eval(input())) +    G = [[] for _ in range(N)] +    for i in range(N - 1): +        u, v, w = list(map(int, input().split())) +        u -= 1 +        v -= 1 +        G[u].append((v, w)) +        G[v].append((u, w)) +    ans = [-1] * N +    ans[0] = 0 +    stack = deque([(-1, 0)]) +    while stack: +        p, u = stack.pop() +        for v, w in G[u]: +            if v == p: +                continue +            if w % 2 == 0: +                ans[v] = ans[u] +            else: +                ans[v] = (ans[u] + 1) % 2 +            stack.append((u, v)) +    print(("\n".join(map(str, ans)))) -dfs(0, 0) -for c in C: -    print(c) +if __name__ == "__main__": +    main()