We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied:    * For any two vertices painted in the same color, the distance between them is an even number.  Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.
N = int(input())

A = []
while True:
    try:
        temp=list(map(int,input().split()))
        A.append(temp)
    except:
        break;

E = set([])
O = set([])

for i in range(len(A)):
  if A[i][2]%2 ==0:
    E.add(A[i][0])
    E.add(A[i][1])
  else:
    if A[i][0] not in E and A[i][0] not in O:
      if A[i][1] in E:
        O.add(A[i][0])
      elif A[i][1] in O:
        E.add(A[i][0])
      else:
        E.add(A[i][0])
        O.add(A[i][1])
    elif A[i][1] not in E and A[i][1] not in O:
      if A[i][0] in E:
        O.add(A[i][1])
      elif A[i][0] in O:
        E.add(A[i][1])

#print(E,O)
for i in range(N):
  if i+1 in E:
    print("1")
  else:
    print("0")
      
from collections import deque

N = int(input())

A = []
while True:
    try:
        temp=list(map(int,input().split()))
        A.append(temp)
    except:
        break;
#print(A)
To = [[] for i in range(N)]
Cost = [[] for i in range(N)]
for i in range(len(A)):
  #print(A[i])
  To[A[i][0]-1].append(A[i][1]-1)
  To[A[i][1]-1].append(A[i][0]-1)
  Cost[A[i][0]-1].append(A[i][2])
  Cost[A[i][1]-1].append(A[i][2])
#print(To,Cost)

ans = [-1]*N 
ans[0] = 0  
Queue = deque([])
Queue.append(0) 

while Queue:
  v = Queue.popleft() 
  for i in range(len(To[v])): 
    u = To[v][i] 
    w = Cost[v][i] 
    if ans[u] != -1: 
      continue
    ans[u] = (ans[v]+w)%2
    Queue.append(u)
print(*ans, sep="\n")