import sys

sys.setrecursionlimit(10**6)

n = int(input())
if n == 1:
    print(1)
else:
    edge=[[] for _ in range(n)]
    for _ in range(n-1):
        u,v,w = map(int,input().split())
        edge[u-1].append((v-1,w%2))
        edge[v-1].append((u-1,w%2))
 
    color =[-1]*n
    def dfs(node,edge):
        for next_node,w in edge[node]:
            if color[next_node] != -1:
                continue
            if w == 1:
                color[next_node] = color[node]^1
            elif w == 0:
                color[next_node] = color[node]
            dfs(next_node,edge)
        
        
    color[0] = 0
    dfs(0,edge)
    print(*color,sep="\n") import sys sys sys.setrecursionlimit(10**6) sys.setrecursionlimit sys setrecursionlimit 10**6 10 6 n = int(input()) n int(input()) int input() input if n == 1:
    print(1)
else:
    edge=[[] for _ in range(n)]
    for _ in range(n-1):
        u,v,w = map(int,input().split())
        edge[u-1].append((v-1,w%2))
        edge[v-1].append((u-1,w%2))
 
    color =[-1]*n
    def dfs(node,edge):
        for next_node,w in edge[node]:
            if color[next_node] != -1:
                continue
            if w == 1:
                color[next_node] = color[node]^1
            elif w == 0:
                color[next_node] = color[node]
            dfs(next_node,edge)
        
        
    color[0] = 0
    dfs(0,edge)
    print(*color,sep="\n") n == 1 n 1 print(1) print 1 [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] edge=[[] for _ in range(n)] edge [[] for _ in range(n)] for _ in range(n-1):
        u,v,w = map(int,input().split())
        edge[u-1].append((v-1,w%2))
        edge[v-1].append((u-1,w%2))
 
     _ range(n-1) range n-1 n 1 u,v,w = map(int,input().split()) u map(int,input().split()) map int input().split() ().split () input split v w edge[u-1].append((v-1,w%2)) [u-1].append [u-1] edge u-1 u 1 append (v-1,w%2) v-1 v 1 w%2 w 2 edge[v-1].append((u-1,w%2)) [v-1].append [v-1] edge v-1 v 1 append (u-1,w%2) u-1 u 1 w%2 w 2 color =[-1]*n color [-1]*n [-1] -1 n def dfs(node,edge):
        for next_node,w in edge[node]:
            if color[next_node] != -1:
                continue
            if w == 1:
                color[next_node] = color[node]^1
            elif w == 0:
                color[next_node] = color[node]
            dfs(next_node,edge)
        
        
     dfs for next_node,w in edge[node]:
            if color[next_node] != -1:
                continue
            if w == 1:
                color[next_node] = color[node]^1
            elif w == 0:
                color[next_node] = color[node]
            dfs(next_node,edge)
        
        
     next_node w edge[node] edge node if color[next_node] != -1:
                continue
             color[next_node] != -1 color[next_node] color next_node -1 continue if w == 1:
                color[next_node] = color[node]^1
            elif w == 0:
                color[next_node] = color[node]
             w == 1 w 1 color[next_node] = color[node]^1 color[next_node] color next_node color[node]^1 color[node] color node 1 elif w == 0:
                color[next_node] = color[node]
             w == 0 w 0 color[next_node] = color[node] color[next_node] color next_node color[node] color node dfs(next_node,edge) dfs next_node edge node node edge edge color[0] = 0 color[0] color 0 0 dfs(0,edge) dfs 0 edge print(*color,sep="\n") print *color color sep="\n" sep "\n" color =[-1]*n [-1]*n color w = map(int,input().split()) map(int,input().split()) w edge=[[] for _ in range(n)] [[] for _ in range(n)] edge u,v,w = map(int,input().split()) map(int,input().split()) u n = int(input()) int(input()) n v,w = map(int,input().split()) map(int,input().split()) v def dfs(node,edge):
        for next_node,w in edge[node]:
            if color[next_node] != -1:
                continue
            if w == 1:
                color[next_node] = color[node]^1
            elif w == 0:
                color[next_node] = color[node]
            dfs(next_node,edge)
        
        
     def dfs(node,edge):
        for next_node,w in edge[node]:
            if color[next_node] != -1:
                continue
            if w == 1:
                color[next_node] = color[node]^1
            elif w == 0:
                color[next_node] = color[node]
            dfs(next_node,edge)
        
        
     dfs
import sys

sys.setrecursionlimit(10**6)

n = int(input())
if n == 1:
    print(1)
else:
    edge=[[] for _ in range(n)]
    for _ in range(n-1):
        u,v,w = map(int,input().split())
        edge[u-1].append((v-1,w%2))
        edge[v-1].append((u-1,w%2))
 
    color =[-1]*n
    def dfs(node,edge):
        for next_node,w in edge[node]:
            if color[next_node] != -1:
                continue
            if w == 1:
                color[next_node] = color[node]^1
            elif w == 0:
                color[next_node] = color[node]
            dfs(next_node,edge)
        
        
    color[0] = 0
    dfs(0,edge)
    print(*color,sep="\n")