def getN():

    return int(eval(input()))

def getNM():

    return list(map(int, input().split()))

def getList():

    return list(map(int, input().split()))



from collections import deque



n = getN()

paths = [[] for i in range(n)]

for i in range(n-1):

    a,b,c = getList()

    paths[a-1].append((b-1,c))

    paths[b-1].append((a-1,c))



def findroot(tree):

    for i, v in enumerate(tree):

        if len(v) == 1:

            return i



root = findroot(paths)





def getdist(tree, root):

    d = deque([root])

    dist = [-1 for i in range(len(tree))]

    dist[root] = 0

    while(d):

        #print(d, dist)

        nxt = d.pop()

        tmp = dist[nxt]

        for edge in tree[nxt]:

            v, c = edge

            if dist[v] == -1:

                d.append(v)

                dist[v] = tmp + c



    return dist



distlist = getdist(paths, root)

for i in distlist:

    print((i % 2))
import sys

input = sys.stdin.readline

sys.setrecursionlimit(1000000)

from collections import deque

def getN():

    return int(eval(input()))

def getList():

    return list(map(int, input().split()))

import math

from collections import deque



n = getN()

tree = [[] for i in range(n)]

visited = [0 for i in range(n)]

color = [0 for i in range(n)]



for i in range(n-1):

    a, b, c = getList()

    tree[a-1].append((b-1, c))

    tree[b-1].append((a-1, c))



for i, vert in enumerate(tree):

    if len(vert) == 1:

        root = i

        break



deq = deque()

deq.append(root)



while(len(deq) != 0):

    cur = deq.pop()

    for (target, dist) in tree[cur]:

        if visited[target] == 0:

            color[target] = (color[cur] + dist) % 2

            visited[target] = 1



            deq.append(target)







for c in color:

    print(c)
def getN():
    return int(eval(input()))


def getNM():
    return list(map(int, input().split()))


def getList():
    return list(map(int, input().split()))


from collections import deque

n = getN()
paths = [[] for i in range(n)]
for i in range(n - 1):
    a, b, c = getList()
    paths[a - 1].append((b - 1, c))
    paths[b - 1].append((a - 1, c))


def findroot(tree):
    for i, v in enumerate(tree):
        if len(v) == 1:
            return i


root = findroot(paths)


def getdist(tree, root):
    d = deque([root])
    dist = [-1 for i in range(len(tree))]
    dist[root] = 0
    while d:
        # print(d, dist)
        nxt = d.pop()
        tmp = dist[nxt]
        for edge in tree[nxt]:
            v, c = edge
            if dist[v] == -1:
                d.append(v)
                dist[v] = tmp + c
    return dist


distlist = getdist(paths, root)
for i in distlist:
    print((i % 2))

import sys

input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque


def getN():
    return int(eval(input()))


def getList():
    return list(map(int, input().split()))


import math
from collections import deque

n = getN()
tree = [[] for i in range(n)]
visited = [0 for i in range(n)]
color = [0 for i in range(n)]
for i in range(n - 1):
    a, b, c = getList()
    tree[a - 1].append((b - 1, c))
    tree[b - 1].append((a - 1, c))
for i, vert in enumerate(tree):
    if len(vert) == 1:
        root = i
        break
deq = deque()
deq.append(root)
while len(deq) != 0:
    cur = deq.pop()
    for (target, dist) in tree[cur]:
        if visited[target] == 0:
            color[target] = (color[cur] + dist) % 2
            visited[target] = 1
            deq.append(target)
for c in color:
    print(c)

+import sys + +input = sys.stdin.readline +sys.setrecursionlimit(1000000) +from collections import deque + + - - -def getNM(): -    return list(map(int, input().split())) +import math -paths = [[] for i in range(n)] +tree = [[] for i in range(n)] +visited = [0 for i in range(n)] +color = [0 for i in range(n)] -    paths[a - 1].append((b - 1, c)) -    paths[b - 1].append((a - 1, c)) - - -def findroot(tree): -    for i, v in enumerate(tree): -        if len(v) == 1: -            return i - - -root = findroot(paths) - - -def getdist(tree, root): -    d = deque([root]) -    dist = [-1 for i in range(len(tree))] -    dist[root] = 0 -    while d: -        # print(d, dist) -        nxt = d.pop() -        tmp = dist[nxt] -        for edge in tree[nxt]: -            v, c = edge -            if dist[v] == -1: -                d.append(v) -                dist[v] = tmp + c -    return dist - - -distlist = getdist(paths, root) -for i in distlist: -    print((i % 2)) +    tree[a - 1].append((b - 1, c)) +    tree[b - 1].append((a - 1, c)) +for i, vert in enumerate(tree): +    if len(vert) == 1: +        root = i +        break +deq = deque() +deq.append(root) +while len(deq) != 0: +    cur = deq.pop() +    for (target, dist) in tree[cur]: +        if visited[target] == 0: +            color[target] = (color[cur] + dist) % 2 +            visited[target] = 1 +            deq.append(target) +for c in color: +    print(c)