from collections import deque
N=int(input())
E={i:{} for i in range(1,N+1)}

for _ in range(N-1):
    u,v,w=map(int,input().split())
    E[u][v]=w%2
    E[v][u]=w%2

inf=float("inf")
Dist=[inf]*(N+1)
Q=deque([1])
Dist[1]=0
while Q:
    u=Q.popleft()
    for v in E[u]:
        if Dist[v]==inf:
            Q.append(v)
            Dist[v]=Dist[u]^E[u][v]
print("\n".join(map(str,Dist[1:]))) from collections import deque N=int(input()) N int(input()) int input() input i:{} for i in range(1,N+1) for i in range(1,N+1) i range(1,N+1) range 1 N+1 N 1 for i in range(1,N+1) i {} E={i:{} for i in range(1,N+1)} E {i:{} for i in range(1,N+1)} for _ in range(N-1):
    u,v,w=map(int,input().split())
    E[u][v]=w%2
    E[v][u]=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 E[u][v]=w%2 E[u][v] [u] E u v w%2 w 2 E[v][u]=w%2 E[v][u] [v] E v u w%2 w 2 inf=float("inf") inf float("inf") float "inf" Dist=[inf]*(N+1) Dist [inf]*(N+1) [inf] inf N+1 N 1 Q=deque([1]) Q deque([1]) deque [1] 1 Dist[1]=0 Dist[1] Dist 1 0 while Q:
    u=Q.popleft()
    for v in E[u]:
        if Dist[v]==inf:
            Q.append(v)
            Dist[v]=Dist[u]^E[u][v] Q u=Q.popleft() u Q.popleft() Q.popleft Q popleft for v in E[u]:
        if Dist[v]==inf:
            Q.append(v)
            Dist[v]=Dist[u]^E[u][v] v E[u] E u if Dist[v]==inf:
            Q.append(v)
            Dist[v]=Dist[u]^E[u][v] Dist[v]==inf Dist[v] Dist v inf Q.append(v) Q.append Q append v Dist[v]=Dist[u]^E[u][v] Dist[v] Dist v Dist[u]^E[u][v] Dist[u] Dist u E[u][v] [u] E u v print("\n".join(map(str,Dist[1:]))) print "\n".join(map(str,Dist[1:])) "\n".join "\n" join map(str,Dist[1:]) map str Dist[1:] Dist 1: 1 E={i:{} for i in range(1,N+1)} {i:{} for i in range(1,N+1)} E Dist=[inf]*(N+1) [inf]*(N+1) Dist u=Q.popleft() Q.popleft() u v,w=map(int,input().split()) map(int,input().split()) v w=map(int,input().split()) map(int,input().split()) w u,v,w=map(int,input().split()) map(int,input().split()) u N=int(input()) int(input()) N Q=deque([1]) deque([1]) Q inf=float("inf") float("inf") inf
from collections import deque
N=int(input())
E={i:{} for i in range(1,N+1)}

for _ in range(N-1):
    u,v,w=map(int,input().split())
    E[u][v]=w%2
    E[v][u]=w%2

inf=float("inf")
Dist=[inf]*(N+1)
Q=deque([1])
Dist[1]=0
while Q:
    u=Q.popleft()
    for v in E[u]:
        if Dist[v]==inf:
            Q.append(v)
            Dist[v]=Dist[u]^E[u][v]
print("\n".join(map(str,Dist[1:])))