'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"


def main():
    n = int(ipt())
    way = [[] for i in range(n+1)]
    for i in range(n-1):
        u,v,w = map(int,ipt().split())
        way[u].append((v,w))
        way[v].append((u,w))

    col = [-1]*(n+1)
    q = [(1,0)]
    col[1] = 0
    while q:
        qi,ci = q.pop()
#        print(qi,ci)
        for j,lj in way[qi]:
            if col[j] == -1:
                cj = (ci+lj)%2
                col[j] = cj
                q.append((j,cj))

    for i in col[1::]:
        print(i)

    return None

if __name__ == '__main__':
    main() '''
研究室PCでの解答
''' import math math import queue queue import bisect bisect from collections import deque,defaultdict import heapq as hpq heapq from sys import stdin,setrecursionlimit ipt = stdin.readline ipt stdin.readline stdin readline setrecursionlimit(10**7) setrecursionlimit 10**7 10 7 mod = 10**9+7 mod 10**9+7 10**9 10 9 7 dir = [(-1,0),(1,0),(0,-1),(0,1)] dir [(-1,0),(1,0),(0,-1),(0,1)] (-1,0) -1 0 (1,0) 1 0 (0,-1) 0 -1 (0,1) 0 1 alp = "abcdefghijklmnopqrstuvwxyz" alp "abcdefghijklmnopqrstuvwxyz" def main():
    n = int(ipt())
    way = [[] for i in range(n+1)]
    for i in range(n-1):
        u,v,w = map(int,ipt().split())
        way[u].append((v,w))
        way[v].append((u,w))

    col = [-1]*(n+1)
    q = [(1,0)]
    col[1] = 0
    while q:
        qi,ci = q.pop()
#        print(qi,ci)
        for j,lj in way[qi]:
            if col[j] == -1:
                cj = (ci+lj)%2
                col[j] = cj
                q.append((j,cj))

    for i in col[1::]:
        print(i)

    return None main n = int(ipt()) n int(ipt()) int ipt() ipt [] for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) [] way = [[] for i in range(n+1)] way [[] for i in range(n+1)] for i in range(n-1):
        u,v,w = map(int,ipt().split())
        way[u].append((v,w))
        way[v].append((u,w))

     i range(n-1) range n-1 n 1 u,v,w = map(int,ipt().split()) u map(int,ipt().split()) map int ipt().split() ().split () ipt split v w way[u].append((v,w)) [u].append [u] way u append (v,w) v w way[v].append((u,w)) [v].append [v] way v append (u,w) u w col = [-1]*(n+1) col [-1]*(n+1) [-1] -1 n+1 n 1 q = [(1,0)] q [(1,0)] (1,0) 1 0 col[1] = 0 col[1] col 1 0 while q:
        qi,ci = q.pop()
#        print(qi,ci)
        for j,lj in way[qi]:
            if col[j] == -1:
                cj = (ci+lj)%2
                col[j] = cj
                q.append((j,cj))

     q qi,ci = q.pop() qi q.pop() q.pop q pop ci for j,lj in way[qi]:
            if col[j] == -1:
                cj = (ci+lj)%2
                col[j] = cj
                q.append((j,cj))

     j lj way[qi] way qi if col[j] == -1:
                cj = (ci+lj)%2
                col[j] = cj
                q.append((j,cj))

     col[j] == -1 col[j] col j -1 cj = (ci+lj)%2 cj (ci+lj)%2 ci+lj ci lj 2 col[j] = cj col[j] col j cj q.append((j,cj)) q.append q append (j,cj) j cj for i in col[1::]:
        print(i)

     i col[1::] col 1:: 1 print(i) print i return None None if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n = int(ipt())
    way = [[] for i in range(n+1)]
    for i in range(n-1):
        u,v,w = map(int,ipt().split())
        way[u].append((v,w))
        way[v].append((u,w))

    col = [-1]*(n+1)
    q = [(1,0)]
    col[1] = 0
    while q:
        qi,ci = q.pop()
#        print(qi,ci)
        for j,lj in way[qi]:
            if col[j] == -1:
                cj = (ci+lj)%2
                col[j] = cj
                q.append((j,cj))

    for i in col[1::]:
        print(i)

    return None def main():
    n = int(ipt())
    way = [[] for i in range(n+1)]
    for i in range(n-1):
        u,v,w = map(int,ipt().split())
        way[u].append((v,w))
        way[v].append((u,w))

    col = [-1]*(n+1)
    q = [(1,0)]
    col[1] = 0
    while q:
        qi,ci = q.pop()
#        print(qi,ci)
        for j,lj in way[qi]:
            if col[j] == -1:
                cj = (ci+lj)%2
                col[j] = cj
                q.append((j,cj))

    for i in col[1::]:
        print(i)

    return None main ipt = stdin.readline stdin.readline ipt dir = [(-1,0),(1,0),(0,-1),(0,1)] [(-1,0),(1,0),(0,-1),(0,1)] dir alp = "abcdefghijklmnopqrstuvwxyz" "abcdefghijklmnopqrstuvwxyz" alp mod = 10**9+7 10**9+7 mod
'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"


def main():
    n = int(ipt())
    way = [[] for i in range(n+1)]
    for i in range(n-1):
        u,v,w = map(int,ipt().split())
        way[u].append((v,w))
        way[v].append((u,w))

    col = [-1]*(n+1)
    q = [(1,0)]
    col[1] = 0
    while q:
        qi,ci = q.pop()
#        print(qi,ci)
        for j,lj in way[qi]:
            if col[j] == -1:
                cj = (ci+lj)%2
                col[j] = cj
                q.append((j,cj))

    for i in col[1::]:
        print(i)

    return None

if __name__ == '__main__':
    main()
