n = int(eval(input()))

data = [[] for _ in range(n)]

for _ in range(n-1):

    a,b,c = list(map(int,input().split()))

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

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



que = []

color = [-1 for _ in range(n)]

def dfs(a,data):

    # pop last index

    #a : current state

    if color[a] == -1:

        color[a] = 0

        que.append(a)

    else:

        return 0

    while len(que):

        a = que.pop()

        for i in data[a]:

            #i[0] is edge

            #i[1] is cost

            if color[i[0]] != -1:continue

        

            if i[1] == 0:

                color[i[0]] = color[a]

            else:

                color[i[0]] = 1 - color[a]  

            que.append(i[0])



for i in range(n):

    dfs(i,data)

for i in range(n):

    print((color[i]))

        
def main():

    ii = lambda : int(eval(input()))

    mi = lambda : list(map(int,input().split()))

    li = lambda : list(map(int,input().split()))

    n = ii()

    v = [[] for _ in range(n)]

    for i in range(n-1):

        u,vv,w = mi()

        v[u-1].append([vv -1,w % 2])

        v[vv-1].append([u -1,w % 2])

    flag = [0] * n

    flag[0] = 1

    ans = [-1] * n

    from collections import deque

    q = deque()

    q.append((0,0))

    ans[0] = 0

    while q:

        ima,ima_col = q.popleft()

        for lis in v[ima]:

            if flag[lis[0]] :continue

            flag[lis[0]] = 1

            if lis[1]:

                ans[lis[0]] = lis[1] - ima_col

                q.append((lis[0],lis[1] - ima_col))

            else:

                ans[lis[0]] = ima_col

                q.append((lis[0],ima_col))

    for i in range(n):

        print((ans[i]))

main()

    

    
n = int(eval(input()))
data = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b, c = list(map(int, input().split()))
    data[a - 1].append([b - 1, c % 2])
    data[b - 1].append([a - 1, c % 2])
que = []
color = [-1 for _ in range(n)]


def dfs(a, data):
    # pop last index
    # a : current state
    if color[a] == -1:
        color[a] = 0
        que.append(a)
    else:
        return 0
    while len(que):
        a = que.pop()
        for i in data[a]:
            # i[0] is edge
            # i[1] is cost
            if color[i[0]] != -1:
                continue
            if i[1] == 0:
                color[i[0]] = color[a]
            else:
                color[i[0]] = 1 - color[a]
            que.append(i[0])


for i in range(n):
    dfs(i, data)
for i in range(n):
    print((color[i]))

def main():
    ii = lambda: int(eval(input()))
    mi = lambda: list(map(int, input().split()))
    li = lambda: list(map(int, input().split()))
    n = ii()
    v = [[] for _ in range(n)]
    for i in range(n - 1):
        u, vv, w = mi()
        v[u - 1].append([vv - 1, w % 2])
        v[vv - 1].append([u - 1, w % 2])
    flag = [0] * n
    flag[0] = 1
    ans = [-1] * n
    from collections import deque

    q = deque()
    q.append((0, 0))
    ans[0] = 0
    while q:
        ima, ima_col = q.popleft()
        for lis in v[ima]:
            if flag[lis[0]]:
                continue
            flag[lis[0]] = 1
            if lis[1]:
                ans[lis[0]] = lis[1] - ima_col
                q.append((lis[0], lis[1] - ima_col))
            else:
                ans[lis[0]] = ima_col
                q.append((lis[0], ima_col))
    for i in range(n):
        print((ans[i]))


main()

-n = int(eval(input())) -data = [[] for _ in range(n)] -for _ in range(n - 1): -    a, b, c = list(map(int, input().split())) -    data[a - 1].append([b - 1, c % 2]) -    data[b - 1].append([a - 1, c % 2]) -que = [] -color = [-1 for _ in range(n)] +def main(): +    ii = lambda: int(eval(input())) +    mi = lambda: list(map(int, input().split())) +    li = lambda: list(map(int, input().split())) +    n = ii() +    v = [[] for _ in range(n)] +    for i in range(n - 1): +        u, vv, w = mi() +        v[u - 1].append([vv - 1, w % 2]) +        v[vv - 1].append([u - 1, w % 2]) +    flag = [0] * n +    flag[0] = 1 +    ans = [-1] * n +    from collections import deque + +    q = deque() +    q.append((0, 0)) +    ans[0] = 0 +    while q: +        ima, ima_col = q.popleft() +        for lis in v[ima]: +            if flag[lis[0]]: +                continue +            flag[lis[0]] = 1 +            if lis[1]: +                ans[lis[0]] = lis[1] - ima_col +                q.append((lis[0], lis[1] - ima_col)) +            else: +                ans[lis[0]] = ima_col +                q.append((lis[0], ima_col)) +    for i in range(n): +        print((ans[i])) -def dfs(a, data): -    # pop last index -    # a : current state -    if color[a] == -1: -        color[a] = 0 -        que.append(a) -    else: -        return 0 -    while len(que): -        a = que.pop() -        for i in data[a]: -            # i[0] is edge -            # i[1] is cost -            if color[i[0]] != -1: -                continue -            if i[1] == 0: -                color[i[0]] = color[a] -            else: -                color[i[0]] = 1 - color[a] -            que.append(i[0]) - - -for i in range(n): -    dfs(i, data) -for i in range(n): -    print((color[i])) +main()