import sys
input = sys.stdin.readline
from collections import deque
def main():
    N = int( input())
    E = [[] for _ in range(N)]
    for _ in range(N-1):
        u, v, w = map( int, input().split())
        u -= 1
        v -= 1
        E[u].append((v,w))
        E[v].append((u,w))
    V = [-1]*N
    V[0] = 0
    d = deque([(0,0)])
    while d:
        u, l = d.popleft()
        for v,w in E[u]:
            if V[v] == -1:
                V[v] = (l+w)%2
                d.append((v, (l+w)%2))
    print("\n".join( map( str, V)))
    
    
if __name__ == '__main__':
    main() import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline from collections import deque def main():
    N = int( input())
    E = [[] for _ in range(N)]
    for _ in range(N-1):
        u, v, w = map( int, input().split())
        u -= 1
        v -= 1
        E[u].append((v,w))
        E[v].append((u,w))
    V = [-1]*N
    V[0] = 0
    d = deque([(0,0)])
    while d:
        u, l = d.popleft()
        for v,w in E[u]:
            if V[v] == -1:
                V[v] = (l+w)%2
                d.append((v, (l+w)%2))
    print("\n".join( map( str, V)))
    
     main N = int( input()) N int( input()) int input() input [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] E = [[] for _ in range(N)] E [[] for _ in range(N)] for _ in range(N-1):
        u, v, w = map( int, input().split())
        u -= 1
        v -= 1
        E[u].append((v,w))
        E[v].append((u,w))
     _ 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 u -= 1 u 1 v -= 1 v 1 E[u].append((v,w)) [u].append [u] E u append (v,w) v w E[v].append((u,w)) [v].append [v] E v append (u,w) u w V = [-1]*N V [-1]*N [-1] -1 N V[0] = 0 V[0] V 0 0 d = deque([(0,0)]) d deque([(0,0)]) deque [(0,0)] (0,0) 0 0 while d:
        u, l = d.popleft()
        for v,w in E[u]:
            if V[v] == -1:
                V[v] = (l+w)%2
                d.append((v, (l+w)%2))
     d u, l = d.popleft() u d.popleft() d.popleft d popleft l for v,w in E[u]:
            if V[v] == -1:
                V[v] = (l+w)%2
                d.append((v, (l+w)%2))
     v w E[u] E u if V[v] == -1:
                V[v] = (l+w)%2
                d.append((v, (l+w)%2))
     V[v] == -1 V[v] V v -1 V[v] = (l+w)%2 V[v] V v (l+w)%2 l+w l w 2 d.append((v, (l+w)%2)) d.append d append (v, (l+w)%2) v (l+w)%2 l+w l w 2 print("\n".join( map( str, V))) print "\n".join( map( str, V)) "\n".join "\n" join map( str, V) map str V if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    N = int( input())
    E = [[] for _ in range(N)]
    for _ in range(N-1):
        u, v, w = map( int, input().split())
        u -= 1
        v -= 1
        E[u].append((v,w))
        E[v].append((u,w))
    V = [-1]*N
    V[0] = 0
    d = deque([(0,0)])
    while d:
        u, l = d.popleft()
        for v,w in E[u]:
            if V[v] == -1:
                V[v] = (l+w)%2
                d.append((v, (l+w)%2))
    print("\n".join( map( str, V)))
    
     def main():
    N = int( input())
    E = [[] for _ in range(N)]
    for _ in range(N-1):
        u, v, w = map( int, input().split())
        u -= 1
        v -= 1
        E[u].append((v,w))
        E[v].append((u,w))
    V = [-1]*N
    V[0] = 0
    d = deque([(0,0)])
    while d:
        u, l = d.popleft()
        for v,w in E[u]:
            if V[v] == -1:
                V[v] = (l+w)%2
                d.append((v, (l+w)%2))
    print("\n".join( map( str, V)))
    
     main input = sys.stdin.readline sys.stdin.readline input
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N = int( input())
    E = [[] for _ in range(N)]
    for _ in range(N-1):
        u, v, w = map( int, input().split())
        u -= 1
        v -= 1
        E[u].append((v,w))
        E[v].append((u,w))
    V = [-1]*N
    V[0] = 0
    d = deque([(0,0)])
    while d:
        u, l = d.popleft()
        for v,w in E[u]:
            if V[v] == -1:
                V[v] = (l+w)%2
                d.append((v, (l+w)%2))
    print("\n".join( map( str, V)))
    
    
if __name__ == '__main__':
    main()
