import sys
sys.setrecursionlimit(10**6)
n=int(input())
path=[[] for i in range(n)]
for i in range(n-1):
    u,v,w=map(int,input().split())
    path[u-1].append((v-1,w%2))
    path[v-1].append((u-1,w%2))
ans=[0]+[-1]*(n-1)
def dfs(i):
    global n,path,ans
    for j in path[i]:
        if ans[j[0]]==-1:
            if j[1]:
                ans[j[0]]=1-ans[i]
                dfs(j[0])
            else:
                ans[j[0]]=ans[i]
                dfs(j[0])
dfs(0)
print("\n".join(map(str,ans))) import sys sys sys.setrecursionlimit(10**6) sys.setrecursionlimit sys setrecursionlimit 10**6 10 6 n=int(input()) n int(input()) int input() input [] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [] path=[[] for i in range(n)] path [[] for i in range(n)] for i in range(n-1):
    u,v,w=map(int,input().split())
    path[u-1].append((v-1,w%2))
    path[v-1].append((u-1,w%2)) i 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 path[u-1].append((v-1,w%2)) [u-1].append [u-1] path u-1 u 1 append (v-1,w%2) v-1 v 1 w%2 w 2 path[v-1].append((u-1,w%2)) [v-1].append [v-1] path v-1 v 1 append (u-1,w%2) u-1 u 1 w%2 w 2 ans=[0]+[-1]*(n-1) ans [0]+[-1]*(n-1) [0] 0 [-1]*(n-1) [-1] -1 n-1 n 1 def dfs(i):
    global n,path,ans
    for j in path[i]:
        if ans[j[0]]==-1:
            if j[1]:
                ans[j[0]]=1-ans[i]
                dfs(j[0])
            else:
                ans[j[0]]=ans[i]
                dfs(j[0]) dfs global n,path,ans for j in path[i]:
        if ans[j[0]]==-1:
            if j[1]:
                ans[j[0]]=1-ans[i]
                dfs(j[0])
            else:
                ans[j[0]]=ans[i]
                dfs(j[0]) j path[i] path i if ans[j[0]]==-1:
            if j[1]:
                ans[j[0]]=1-ans[i]
                dfs(j[0])
            else:
                ans[j[0]]=ans[i]
                dfs(j[0]) ans[j[0]]==-1 ans[j[0]] ans j[0] j 0 -1 if j[1]:
                ans[j[0]]=1-ans[i]
                dfs(j[0])
            else:
                ans[j[0]]=ans[i]
                dfs(j[0]) j[1] j 1 ans[j[0]]=1-ans[i] ans[j[0]] ans j[0] j 0 1-ans[i] 1 ans[i] ans i dfs(j[0]) dfs j[0] j 0 ans[j[0]]=ans[i] ans[j[0]] ans j[0] j 0 ans[i] ans i dfs(j[0]) dfs j[0] j 0 i i dfs(0) dfs 0 print("\n".join(map(str,ans))) print "\n".join(map(str,ans)) "\n".join "\n" join map(str,ans) map str ans path=[[] for i in range(n)] [[] for i in range(n)] path w=map(int,input().split()) map(int,input().split()) w ans=[0]+[-1]*(n-1) [0]+[-1]*(n-1) ans n=int(input()) int(input()) n v,w=map(int,input().split()) map(int,input().split()) v u,v,w=map(int,input().split()) map(int,input().split()) u def dfs(i):
    global n,path,ans
    for j in path[i]:
        if ans[j[0]]==-1:
            if j[1]:
                ans[j[0]]=1-ans[i]
                dfs(j[0])
            else:
                ans[j[0]]=ans[i]
                dfs(j[0]) def dfs(i):
    global n,path,ans
    for j in path[i]:
        if ans[j[0]]==-1:
            if j[1]:
                ans[j[0]]=1-ans[i]
                dfs(j[0])
            else:
                ans[j[0]]=ans[i]
                dfs(j[0]) dfs
import sys
sys.setrecursionlimit(10**6)
n=int(input())
path=[[] for i in range(n)]
for i in range(n-1):
    u,v,w=map(int,input().split())
    path[u-1].append((v-1,w%2))
    path[v-1].append((u-1,w%2))
ans=[0]+[-1]*(n-1)
def dfs(i):
    global n,path,ans
    for j in path[i]:
        if ans[j[0]]==-1:
            if j[1]:
                ans[j[0]]=1-ans[i]
                dfs(j[0])
            else:
                ans[j[0]]=ans[i]
                dfs(j[0])
dfs(0)
print("\n".join(map(str,ans)))