import sys

from collections import deque



read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60





def main():

    N = int(readline())

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

    for _ in range(N - 1):

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

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

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



    color = [0] * N



    def dfs(v, p, c):

        color[v] = c

        for nv, w in G[v]:

            if nv == p:

                continue

            if w % 2:

                dfs(nv, v, 1 - c)

            else:

                dfs(nv, v, c)



    dfs(0, -1, 0)

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

    return





if __name__ == '__main__':

    main()

import sys

from heapq import heappush, heappop



read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

MOD = 1000000007





def main():

    N, *UVW = map(int, read().split())

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

    for u, v, w in zip(*[iter(UVW)] * 3):

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

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



    dist = [INF] * N

    dist[0] = 0

    hq = [(0, 0)]



    while hq:

        d, v = heappop(hq)

        if d > dist[v]:

            continue

        for nv, cost in G[v]:

            if dist[nv] > dist[v] + cost:

                dist[nv] = dist[v] + cost

                heappush(hq, (dist[nv], nv))



    ans = [0] * N

    for i in range(N):

        ans[i] = 0 if dist[i] % 2 == 0 else 1



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

    return





if __name__ == '__main__':

    main()

import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60


def main():
    N = int(readline())
    G = [[] for _ in range(N)]
    for _ in range(N - 1):
        u, v, w = map(int, readline().split())
        G[u - 1].append((v - 1, w))
        G[v - 1].append((u - 1, w))
    color = [0] * N

    def dfs(v, p, c):
        color[v] = c
        for nv, w in G[v]:
            if nv == p:
                continue
            if w % 2:
                dfs(nv, v, 1 - c)
            else:
                dfs(nv, v, c)

    dfs(0, -1, 0)
    print(*color, sep="\n")
    return


if __name__ == "__main__":
    main()

import sys
from heapq import heappush, heappop

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *UVW = map(int, read().split())
    G = [[] for _ in range(N)]
    for u, v, w in zip(*[iter(UVW)] * 3):
        G[u - 1].append((v - 1, w))
        G[v - 1].append((u - 1, w))
    dist = [INF] * N
    dist[0] = 0
    hq = [(0, 0)]
    while hq:
        d, v = heappop(hq)
        if d > dist[v]:
            continue
        for nv, cost in G[v]:
            if dist[nv] > dist[v] + cost:
                dist[nv] = dist[v] + cost
                heappush(hq, (dist[nv], nv))
    ans = [0] * N
    for i in range(N):
        ans[i] = 0 if dist[i] % 2 == 0 else 1
    print(*ans, sep="\n")
    return


if __name__ == "__main__":
    main()

-from collections import deque +from heapq import heappush, heappop +MOD = 1000000007 -    N = int(readline()) +    N, *UVW = map(int, read().split()) -    for _ in range(N - 1): -        u, v, w = map(int, readline().split()) +    for u, v, w in zip(*[iter(UVW)] * 3): -    color = [0] * N - -    def dfs(v, p, c): -        color[v] = c -        for nv, w in G[v]: -            if nv == p: -                continue -            if w % 2: -                dfs(nv, v, 1 - c) -            else: -                dfs(nv, v, c) - -    dfs(0, -1, 0) -    print(*color, sep="\n") +    dist = [INF] * N +    dist[0] = 0 +    hq = [(0, 0)] +    while hq: +        d, v = heappop(hq) +        if d > dist[v]: +            continue +        for nv, cost in G[v]: +            if dist[nv] > dist[v] + cost: +                dist[nv] = dist[v] + cost +                heappush(hq, (dist[nv], nv)) +    ans = [0] * N +    for i in range(N): +        ans[i] = 0 if dist[i] % 2 == 0 else 1 +    print(*ans, sep="\n")