from collections import deque,defaultdict

n=int(input())

routes=[tuple(map(int,input().split())) for i in range(n-1)]



edges=defaultdict(list)

for v1,v2,dist in routes:

  edges[v1-1].append([v2-1,dist])

  edges[v2-1].append([v1-1,dist])

#print(edges)



ans=[0]*n

q=deque([0])

while q:

  v=q.popleft()

  #print(v)

  if ans[v]==0:

    color=[1,0]

  else:

    color=[0,1]

  #print(edges)

  for edge in edges[v]:

    v2=edge[0]

    dist=edge[1]

    edges[v2].remove([v,dist])

    q.append(v2)

    if dist%2==1:

      ans[v2]=color[0]

    else:

      ans[v2]=color[1]

      

print(*ans,sep='\n')        

import sys

sys.setrecursionlimit(10000000)

MOD = 10 ** 9 + 7

INF = 10 ** 15



def main():

    N = int(eval(input()))

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

    for _ in range(N - 1):

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

        a -= 1

        b -= 1

        G[a].append((b,c))

        G[b].append((a,c))

    

    color = [0] * N

    dist = [-1] * N

    stack = [0]

    dist[0] = 0

    while stack:

        v = stack.pop()

        for e,c in G[v]:

            if dist[e] >= 0:

                continue

            dist[e] = dist[v] + c

            color[e] = dist[e]%2

            stack.append(e)

    print(('\n'.join(map(str,color))))

if __name__ == '__main__':

    main()
from collections import deque, defaultdict

n = int(input())
routes = [tuple(map(int, input().split())) for i in range(n - 1)]
edges = defaultdict(list)
for v1, v2, dist in routes:
    edges[v1 - 1].append([v2 - 1, dist])
    edges[v2 - 1].append([v1 - 1, dist])
# print(edges)
ans = [0] * n
q = deque([0])
while q:
    v = q.popleft()
    # print(v)
    if ans[v] == 0:
        color = [1, 0]
    else:
        color = [0, 1]
    # print(edges)
    for edge in edges[v]:
        v2 = edge[0]
        dist = edge[1]
        edges[v2].remove([v, dist])
        q.append(v2)
        if dist % 2 == 1:
            ans[v2] = color[0]
        else:
            ans[v2] = color[1]
print(*ans, sep="\n")

import sys

sys.setrecursionlimit(10000000)
MOD = 10**9 + 7
INF = 10**15


def main():
    N = int(eval(input()))
    G = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b, c = list(map(int, input().split()))
        a -= 1
        b -= 1
        G[a].append((b, c))
        G[b].append((a, c))
    color = [0] * N
    dist = [-1] * N
    stack = [0]
    dist[0] = 0
    while stack:
        v = stack.pop()
        for e, c in G[v]:
            if dist[e] >= 0:
                continue
            dist[e] = dist[v] + c
            color[e] = dist[e] % 2
            stack.append(e)
    print(("\n".join(map(str, color))))


if __name__ == "__main__":
    main()

-from collections import deque, defaultdict +import sys -n = int(input()) -routes = [tuple(map(int, input().split())) for i in range(n - 1)] -edges = defaultdict(list) -for v1, v2, dist in routes: -    edges[v1 - 1].append([v2 - 1, dist]) -    edges[v2 - 1].append([v1 - 1, dist]) -# print(edges) -ans = [0] * n -q = deque([0]) -while q: -    v = q.popleft() -    # print(v) -    if ans[v] == 0: -        color = [1, 0] -    else: -        color = [0, 1] -    # print(edges) -    for edge in edges[v]: -        v2 = edge[0] -        dist = edge[1] -        edges[v2].remove([v, dist]) -        q.append(v2) -        if dist % 2 == 1: -            ans[v2] = color[0] -        else: -            ans[v2] = color[1] -print(*ans, sep="\n") +sys.setrecursionlimit(10000000) +MOD = 10**9 + 7 +INF = 10**15 + + +def main(): +    N = int(eval(input())) +    G = [[] for _ in range(N)] +    for _ in range(N - 1): +        a, b, c = list(map(int, input().split())) +        a -= 1 +        b -= 1 +        G[a].append((b, c)) +        G[b].append((a, c)) +    color = [0] * N +    dist = [-1] * N +    stack = [0] +    dist[0] = 0 +    while stack: +        v = stack.pop() +        for e, c in G[v]: +            if dist[e] >= 0: +                continue +            dist[e] = dist[v] + c +            color[e] = dist[e] % 2 +            stack.append(e) +    print(("\n".join(map(str, color)))) + + +if __name__ == "__main__": +    main()