n = int(eval(input()))

pea = [[] for _ in range(n + 1)]

for _ in range(n - 1):

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

    w %= 2

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

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

ans = [-1] * (n + 1)

ans[1]=1

nodes=[1]

used=set()

used.add(1)

ansi=1

while nodes:

    nn=[]

    for i in nodes:

        ansi=ans[i]

        for u,w in pea[i]:

            if u in used:continue

            ans[u]=(ansi+w)%2

            used.add(u)

            nn+=[u]

    nodes=nn

for x in ans[1:]:

    print(x)
import sys

from collections import defaultdict

sys.setrecursionlimit(10 ** 6)



def main():

    def dfs(i=0,oi=-1):

        for ki,w in to[i]:

            if ki==oi:continue

            ans[ki]=(ans[i]+w)%2

            dfs(ki,i)



    n=int(eval(input()))

    to=defaultdict(list)

    for _ in range(n-1):

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

        u,v=u-1,v-1

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

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

    ans=[-1]*n

    ans[0]=0

    dfs()

    for x in ans:

        print(x)

main()

n = int(eval(input()))
pea = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    u, v, w = list(map(int, input().split()))
    w %= 2
    pea[u].append([v, w])
    pea[v].append([u, w])
ans = [-1] * (n + 1)
ans[1] = 1
nodes = [1]
used = set()
used.add(1)
ansi = 1
while nodes:
    nn = []
    for i in nodes:
        ansi = ans[i]
        for u, w in pea[i]:
            if u in used:
                continue
            ans[u] = (ansi + w) % 2
            used.add(u)
            nn += [u]
    nodes = nn
for x in ans[1:]:
    print(x)

import sys
from collections import defaultdict

sys.setrecursionlimit(10**6)


def main():
    def dfs(i=0, oi=-1):
        for ki, w in to[i]:
            if ki == oi:
                continue
            ans[ki] = (ans[i] + w) % 2
            dfs(ki, i)

    n = int(eval(input()))
    to = defaultdict(list)
    for _ in range(n - 1):
        u, v, w = list(map(int, input().split()))
        u, v = u - 1, v - 1
        to[u].append([v, w])
        to[v].append([u, w])
    ans = [-1] * n
    ans[0] = 0
    dfs()
    for x in ans:
        print(x)


main()

-n = int(eval(input())) -pea = [[] for _ in range(n + 1)] -for _ in range(n - 1): -    u, v, w = list(map(int, input().split())) -    w %= 2 -    pea[u].append([v, w]) -    pea[v].append([u, w]) -ans = [-1] * (n + 1) -ans[1] = 1 -nodes = [1] -used = set() -used.add(1) -ansi = 1 -while nodes: -    nn = [] -    for i in nodes: -        ansi = ans[i] -        for u, w in pea[i]: -            if u in used: +import sys +from collections import defaultdict + +sys.setrecursionlimit(10**6) + + +def main(): +    def dfs(i=0, oi=-1): +        for ki, w in to[i]: +            if ki == oi: -            ans[u] = (ansi + w) % 2 -            used.add(u) -            nn += [u] -    nodes = nn -for x in ans[1:]: -    print(x) +            ans[ki] = (ans[i] + w) % 2 +            dfs(ki, i) + +    n = int(eval(input())) +    to = defaultdict(list) +    for _ in range(n - 1): +        u, v, w = list(map(int, input().split())) +        u, v = u - 1, v - 1 +        to[u].append([v, w]) +        to[v].append([u, w]) +    ans = [-1] * n +    ans[0] = 0 +    dfs() +    for x in ans: +        print(x) + + +main()