import sys

def main():

    input = sys.stdin.readline

    N = int(eval(input()))

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

    for _ in range(N-1):

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

        u,v = u-1,v-1

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

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



    ans = [-1] * N

    ans[0] = 0

    stack = [(0,0)]

    while stack:

        v, w = stack.pop()

        for to, to_w in G[v]:

            if ans[to] >= 0: continue

            ans[to] = 1 if (w + to_w) & 1 else 0

            stack.append((to, w + to_w))

    

    for a in ans: print(a)



if __name__ == '__main__':

    main()
def main():

    import sys

    input = sys.stdin.buffer.readline

    N = int(input())

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

    for i in range(N-1):

        a, b, c = (int(i) for i in input().split())

        edge[a-1].append((c % 2, b-1))

        edge[b-1].append((c % 2, a-1))



    dist = [-1]*N

    color = [-1]*N



    def dfs(v, G):

        todo = []

        dist[v] = 0

        color[v] = 0

        todo.append((v, 0)) #最初は0でappend

        while todo:

            u, s = todo.pop() #ここでpopしちゃう

            if s == 0:

                # s==0: 潜っていく時の処理

                todo.append((u, 1)) #1でappendして戻り処理の仕込み

                for c, next_v in G[u]:

                    if dist[next_v] != -1:

                        continue

                    dist[next_v] = dist[u] + c

                    if dist[next_v] % 2 == 1:

                        color[next_v] = 1

                    else:

                        color[next_v] = 0

                    todo.append((next_v, 0))

                    #break

            #else:

            #    s==1: 戻ってくる時の処理(この問題では特にやることなし)



    dfs(0, edge)

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

    # print("\n", *dist, sep="\n")





if __name__ == '__main__':

    main()

import sys


def main():
    input = sys.stdin.readline
    N = int(eval(input()))
    G = [[] for _ in range(N)]
    for _ in range(N - 1):
        u, v, w = list(map(int, input().split()))
        u, v = u - 1, v - 1
        G[u].append((v, w))
        G[v].append((u, w))
    ans = [-1] * N
    ans[0] = 0
    stack = [(0, 0)]
    while stack:
        v, w = stack.pop()
        for to, to_w in G[v]:
            if ans[to] >= 0:
                continue
            ans[to] = 1 if (w + to_w) & 1 else 0
            stack.append((to, w + to_w))
    for a in ans:
        print(a)


if __name__ == "__main__":
    main()

def main():
    import sys

    input = sys.stdin.buffer.readline
    N = int(input())
    edge = [[] for _ in range(N)]
    for i in range(N - 1):
        a, b, c = (int(i) for i in input().split())
        edge[a - 1].append((c % 2, b - 1))
        edge[b - 1].append((c % 2, a - 1))
    dist = [-1] * N
    color = [-1] * N

    def dfs(v, G):
        todo = []
        dist[v] = 0
        color[v] = 0
        todo.append((v, 0))  # 最初は0でappend
        while todo:
            u, s = todo.pop()  # ここでpopしちゃう
            if s == 0:
                # s==0: 潜っていく時の処理
                todo.append((u, 1))  # 1でappendして戻り処理の仕込み
                for c, next_v in G[u]:
                    if dist[next_v] != -1:
                        continue
                    dist[next_v] = dist[u] + c
                    if dist[next_v] % 2 == 1:
                        color[next_v] = 1
                    else:
                        color[next_v] = 0
                    todo.append((next_v, 0))
                    # break
            # else:
            #    s==1: 戻ってくる時の処理(この問題では特にやることなし)

    dfs(0, edge)
    print(*color, sep="\n")
    # print("\n", *dist, sep="\n")


if __name__ == "__main__":
    main()

-import sys +def main(): +    import sys +    input = sys.stdin.buffer.readline +    N = int(input()) +    edge = [[] for _ in range(N)] +    for i in range(N - 1): +        a, b, c = (int(i) for i in input().split()) +        edge[a - 1].append((c % 2, b - 1)) +        edge[b - 1].append((c % 2, a - 1)) +    dist = [-1] * N +    color = [-1] * N -def main(): -    input = sys.stdin.readline -    N = int(eval(input())) -    G = [[] for _ in range(N)] -    for _ in range(N - 1): -        u, v, w = list(map(int, input().split())) -        u, v = u - 1, v - 1 -        G[u].append((v, w)) -        G[v].append((u, w)) -    ans = [-1] * N -    ans[0] = 0 -    stack = [(0, 0)] -    while stack: -        v, w = stack.pop() -        for to, to_w in G[v]: -            if ans[to] >= 0: -                continue -            ans[to] = 1 if (w + to_w) & 1 else 0 -            stack.append((to, w + to_w)) -    for a in ans: -        print(a) +    def dfs(v, G): +        todo = [] +        dist[v] = 0 +        color[v] = 0 +        todo.append((v, 0))  # 最初は0でappend +        while todo: +            u, s = todo.pop()  # ここでpopしちゃう +            if s == 0: +                # s==0: 潜っていく時の処理 +                todo.append((u, 1))  # 1でappendして戻り処理の仕込み +                for c, next_v in G[u]: +                    if dist[next_v] != -1: +                        continue +                    dist[next_v] = dist[u] + c +                    if dist[next_v] % 2 == 1: +                        color[next_v] = 1 +                    else: +                        color[next_v] = 0 +                    todo.append((next_v, 0)) +                    # break +            # else: +            #    s==1: 戻ってくる時の処理(この問題では特にやることなし) + +    dfs(0, edge) +    print(*color, sep="\n") +    # print("\n", *dist, sep="\n")