import sys

import heapq

input = sys.stdin.readline





def dijkstra(s, n, edge):

    d = [float("inf")] * n

    d[s] = 0

    q = []

    for e in edge[s]:

        heapq.heappush(q, e)

    while q:

        minedge = heapq.heappop(q)

        v = minedge[1]

        if d[v] < minedge[0]:

            continue

        d[v] = minedge[0]

        for e in edge[v]:

            heapq.heappush(q, [e[0]+d[v], e[1]])

    return d





def main():

    N = int(eval(input()))

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

    for _ in range(N-1):

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

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

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

    D = dijkstra(0, N, E)

    for d in D:

        print((d % 2))





if __name__ == '__main__':

    main()

import sys

input = sys.stdin.readline

sys.setrecursionlimit(10**5)





N = int(eval(input()))

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

for _ in range(N-1):

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

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

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

ans = [0]*N





def dfs(v, p, c):

    global ans

    ans[v] = c

    for e in G[v]:

        nv, cost = e

        if nv == p:

            continue

        if (cost % 2) == 0:

            dfs(nv, v, c)

        else:

            dfs(nv, v, (c+1) % 2)





def main():

    dfs(0, -1, 0)

    for c in ans:

        print(c)





if __name__ == '__main__':

    main()

import sys
import heapq

input = sys.stdin.readline


def dijkstra(s, n, edge):
    d = [float("inf")] * n
    d[s] = 0
    q = []
    for e in edge[s]:
        heapq.heappush(q, e)
    while q:
        minedge = heapq.heappop(q)
        v = minedge[1]
        if d[v] < minedge[0]:
            continue
        d[v] = minedge[0]
        for e in edge[v]:
            heapq.heappush(q, [e[0] + d[v], e[1]])
    return d


def main():
    N = int(eval(input()))
    E = [[] for _ in range(N)]
    for _ in range(N - 1):
        u, v, w = list(map(int, input().split()))
        E[u - 1].append([w, v - 1])
        E[v - 1].append([w, u - 1])
    D = dijkstra(0, N, E)
    for d in D:
        print((d % 2))


if __name__ == "__main__":
    main()

import sys

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


def dfs(v, p, c):
    global ans
    ans[v] = c
    for e in G[v]:
        nv, cost = e
        if nv == p:
            continue
        if (cost % 2) == 0:
            dfs(nv, v, c)
        else:
            dfs(nv, v, (c + 1) % 2)


def main():
    dfs(0, -1, 0)
    for c in ans:
        print(c)


if __name__ == "__main__":
    main()

-import heapq +sys.setrecursionlimit(10**5) +N = int(eval(input())) +G = [[] for _ in range(N)] +for _ in range(N - 1): +    u, v, w = list(map(int, input().split())) +    G[u - 1].append([v - 1, w]) +    G[v - 1].append([u - 1, w]) +ans = [0] * N -def dijkstra(s, n, edge): -    d = [float("inf")] * n -    d[s] = 0 -    q = [] -    for e in edge[s]: -        heapq.heappush(q, e) -    while q: -        minedge = heapq.heappop(q) -        v = minedge[1] -        if d[v] < minedge[0]: +def dfs(v, p, c): +    global ans +    ans[v] = c +    for e in G[v]: +        nv, cost = e +        if nv == p: -        d[v] = minedge[0] -        for e in edge[v]: -            heapq.heappush(q, [e[0] + d[v], e[1]]) -    return d +        if (cost % 2) == 0: +            dfs(nv, v, c) +        else: +            dfs(nv, v, (c + 1) % 2) -    N = int(eval(input())) -    E = [[] for _ in range(N)] -    for _ in range(N - 1): -        u, v, w = list(map(int, input().split())) -        E[u - 1].append([w, v - 1]) -        E[v - 1].append([w, u - 1]) -    D = dijkstra(0, N, E) -    for d in D: -        print((d % 2)) +    dfs(0, -1, 0) +    for c in ans: +        print(c)