from collections import defaultdict, deque

N = int( eval(input()))

d = defaultdict( int)

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

for _ in range(N-1):

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

    u = u-1

    v = v-1

    E[u].append(v)

    E[v].append(u)

    d[(u,v)] = w%2

    d[(v,u)] = w%2

V = [-1]*N

V[0] = 0

q = deque([0])

while q:

    v = q.popleft()

    l = V[v]

    for t in E[v]:

        if V[t] == -1:

            V[t] = (l+d[(v,t)])%2

            q.append(t)

for i in range(N):

    print((V[i]))

import sys

input = sys.stdin.readline

from collections import deque

def main():

    N = int( eval(input()))

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

    for _ in range(N-1):

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

        u -= 1

        v -= 1

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

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

    V = [-1]*N

    V[0] = 0

    d = deque([(0,0)])

    while d:

        u, l = d.popleft()

        for v,w in E[u]:

            if V[v] == -1:

                V[v] = (l+w)%2

                d.append((v, (l+w)%2))

    print(("\n".join( map( str, V))))

    

    

if __name__ == '__main__':

    main()

from collections import defaultdict, deque

N = int(eval(input()))
d = defaultdict(int)
E = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v, w = list(map(int, input().split()))
    u = u - 1
    v = v - 1
    E[u].append(v)
    E[v].append(u)
    d[(u, v)] = w % 2
    d[(v, u)] = w % 2
V = [-1] * N
V[0] = 0
q = deque([0])
while q:
    v = q.popleft()
    l = V[v]
    for t in E[v]:
        if V[t] == -1:
            V[t] = (l + d[(v, t)]) % 2
            q.append(t)
for i in range(N):
    print((V[i]))

import sys

input = sys.stdin.readline
from collections import deque


def main():
    N = int(eval(input()))
    E = [[] for _ in range(N)]
    for _ in range(N - 1):
        u, v, w = list(map(int, input().split()))
        u -= 1
        v -= 1
        E[u].append((v, w))
        E[v].append((u, w))
    V = [-1] * N
    V[0] = 0
    d = deque([(0, 0)])
    while d:
        u, l = d.popleft()
        for v, w in E[u]:
            if V[v] == -1:
                V[v] = (l + w) % 2
                d.append((v, (l + w) % 2))
    print(("\n".join(map(str, V))))


if __name__ == "__main__":
    main()

-from collections import defaultdict, deque +import sys -N = int(eval(input())) -d = defaultdict(int) -E = [[] for _ in range(N)] -for _ in range(N - 1): -    u, v, w = list(map(int, input().split())) -    u = u - 1 -    v = v - 1 -    E[u].append(v) -    E[v].append(u) -    d[(u, v)] = w % 2 -    d[(v, u)] = w % 2 -V = [-1] * N -V[0] = 0 -q = deque([0]) -while q: -    v = q.popleft() -    l = V[v] -    for t in E[v]: -        if V[t] == -1: -            V[t] = (l + d[(v, t)]) % 2 -            q.append(t) -for i in range(N): -    print((V[i])) +input = sys.stdin.readline +from collections import deque + + +def main(): +    N = int(eval(input())) +    E = [[] for _ in range(N)] +    for _ in range(N - 1): +        u, v, w = list(map(int, input().split())) +        u -= 1 +        v -= 1 +        E[u].append((v, w)) +        E[v].append((u, w)) +    V = [-1] * N +    V[0] = 0 +    d = deque([(0, 0)]) +    while d: +        u, l = d.popleft() +        for v, w in E[u]: +            if V[v] == -1: +                V[v] = (l + w) % 2 +                d.append((v, (l + w) % 2)) +    print(("\n".join(map(str, V)))) + + +if __name__ == "__main__": +    main()