def main():

    N=int(input())

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

    for _ in range(N-1):

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

        u,v = u-1,v-1

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

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

    color = [-1]*N

    color[0]=0

    stack = [(0,0)]

    while stack:

        v,col = stack.pop()

        for to,dist in edge[v]:

            if color[to]!=-1:

                continue

            c = (col+dist)%2  # 色

            color[to] = c

            stack.append((to,c))

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

            



if __name__ == '__main__':

    main()

import sys

input = sys.stdin.readline

def main():

    N=int(input())

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

    for _ in range(N-1):

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

        u,v = u-1,v-1

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

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

    color = [-1]*N

    color[0]=0

    stack = [(0,0)]

    while stack:

        v,col = stack.pop()

        for to,dist in edge[v]:

            if color[to]!=-1:

                continue

            c = (col+dist)%2  # 色

            color[to] = c

            stack.append((to,c))

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

            



if __name__ == '__main__':

    main()

def main():
    N = int(input())
    edge = [[] for _ in range(N)]
    for _ in range(N - 1):
        u, v, w = map(int, input().split())
        u, v = u - 1, v - 1
        edge[u].append((v, w))
        edge[v].append((u, w))
    color = [-1] * N
    color[0] = 0
    stack = [(0, 0)]
    while stack:
        v, col = stack.pop()
        for to, dist in edge[v]:
            if color[to] != -1:
                continue
            c = (col + dist) % 2  # 色
            color[to] = c
            stack.append((to, c))
    print(*color, sep="\n")


if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline


def main():
    N = int(input())
    edge = [[] for _ in range(N)]
    for _ in range(N - 1):
        u, v, w = map(int, input().split())
        u, v = u - 1, v - 1
        edge[u].append((v, w))
        edge[v].append((u, w))
    color = [-1] * N
    color[0] = 0
    stack = [(0, 0)]
    while stack:
        v, col = stack.pop()
        for to, dist in edge[v]:
            if color[to] != -1:
                continue
            c = (col + dist) % 2  # 色
            color[to] = c
            stack.append((to, c))
    print(*color, sep="\n")


if __name__ == "__main__":
    main()

+import sys + +input = sys.stdin.readline + +