import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
from collections import deque
#======================================================#
def main():
    n = II()
    graph = [[] for _ in range(n)]
    for i in range(n-1):
        u,v,w = MII()
        graph[u-1].append((w, v-1))
        graph[v-1].append((w, u-1))
    dq = deque()
    color = [-1]*n
    dist = [-1]*n
    dq.append((0,0))
    color[0] = 0
    dist[0] = 0
    while dq:
        prev_cost, src = dq.popleft()
        for cost, dst in graph[src]:
            if dist[dst] != -1:
                continue
            if prev_cost%2 == cost%2:
                color[dst] = 0
            else:
                color[dst] = 1
            dist[dst] = dist[src] + cost
            dq.append((dist[dst], dst))
    print(*color, sep='\n')

if __name__ == '__main__':
    main() import sys sys def IS(): return sys.stdin.readline().rstrip() IS def II(): return int(IS()) II def MII(): return list(map(int, IS().split())) MII def MIIZ(): return list(map(lambda x: x-1, MII())) MIIZ from collections import deque def main():
    n = II()
    graph = [[] for _ in range(n)]
    for i in range(n-1):
        u,v,w = MII()
        graph[u-1].append((w, v-1))
        graph[v-1].append((w, u-1))
    dq = deque()
    color = [-1]*n
    dist = [-1]*n
    dq.append((0,0))
    color[0] = 0
    dist[0] = 0
    while dq:
        prev_cost, src = dq.popleft()
        for cost, dst in graph[src]:
            if dist[dst] != -1:
                continue
            if prev_cost%2 == cost%2:
                color[dst] = 0
            else:
                color[dst] = 1
            dist[dst] = dist[src] + cost
            dq.append((dist[dst], dst))
    print(*color, sep='\n') main n = II() n II() II [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] graph = [[] for _ in range(n)] graph [[] for _ in range(n)] for i in range(n-1):
        u,v,w = MII()
        graph[u-1].append((w, v-1))
        graph[v-1].append((w, u-1))
     i range(n-1) range n-1 n 1 u,v,w = MII() u MII() MII v w graph[u-1].append((w, v-1)) [u-1].append [u-1] graph u-1 u 1 append (w, v-1) w v-1 v 1 graph[v-1].append((w, u-1)) [v-1].append [v-1] graph v-1 v 1 append (w, u-1) w u-1 u 1 dq = deque() dq deque() deque color = [-1]*n color [-1]*n [-1] -1 n dist = [-1]*n dist [-1]*n [-1] -1 n dq.append((0,0)) dq.append dq append (0,0) 0 0 color[0] = 0 color[0] color 0 0 dist[0] = 0 dist[0] dist 0 0 while dq:
        prev_cost, src = dq.popleft()
        for cost, dst in graph[src]:
            if dist[dst] != -1:
                continue
            if prev_cost%2 == cost%2:
                color[dst] = 0
            else:
                color[dst] = 1
            dist[dst] = dist[src] + cost
            dq.append((dist[dst], dst))
     dq prev_cost, src = dq.popleft() prev_cost dq.popleft() dq.popleft dq popleft src for cost, dst in graph[src]:
            if dist[dst] != -1:
                continue
            if prev_cost%2 == cost%2:
                color[dst] = 0
            else:
                color[dst] = 1
            dist[dst] = dist[src] + cost
            dq.append((dist[dst], dst))
     cost dst graph[src] graph src if dist[dst] != -1:
                continue
             dist[dst] != -1 dist[dst] dist dst -1 continue if prev_cost%2 == cost%2:
                color[dst] = 0
            else:
                color[dst] = 1
             prev_cost%2 == cost%2 prev_cost%2 prev_cost 2 cost%2 cost 2 color[dst] = 0 color[dst] color dst 0 color[dst] = 1 color[dst] color dst 1 dist[dst] = dist[src] + cost dist[dst] dist dst dist[src] + cost dist[src] dist src cost dq.append((dist[dst], dst)) dq.append dq append (dist[dst], dst) dist[dst] dist dst dst print(*color, sep='\n') print *color color sep='\n' sep '\n' if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def MII(): return list(map(int, IS().split())) def MII(): return list(map(int, IS().split())) MII def IS(): return sys.stdin.readline().rstrip() def IS(): return sys.stdin.readline().rstrip() IS def II(): return int(IS()) def II(): return int(IS()) II def MIIZ(): return list(map(lambda x: x-1, MII())) def MIIZ(): return list(map(lambda x: x-1, MII())) MIIZ def main():
    n = II()
    graph = [[] for _ in range(n)]
    for i in range(n-1):
        u,v,w = MII()
        graph[u-1].append((w, v-1))
        graph[v-1].append((w, u-1))
    dq = deque()
    color = [-1]*n
    dist = [-1]*n
    dq.append((0,0))
    color[0] = 0
    dist[0] = 0
    while dq:
        prev_cost, src = dq.popleft()
        for cost, dst in graph[src]:
            if dist[dst] != -1:
                continue
            if prev_cost%2 == cost%2:
                color[dst] = 0
            else:
                color[dst] = 1
            dist[dst] = dist[src] + cost
            dq.append((dist[dst], dst))
    print(*color, sep='\n') def main():
    n = II()
    graph = [[] for _ in range(n)]
    for i in range(n-1):
        u,v,w = MII()
        graph[u-1].append((w, v-1))
        graph[v-1].append((w, u-1))
    dq = deque()
    color = [-1]*n
    dist = [-1]*n
    dq.append((0,0))
    color[0] = 0
    dist[0] = 0
    while dq:
        prev_cost, src = dq.popleft()
        for cost, dst in graph[src]:
            if dist[dst] != -1:
                continue
            if prev_cost%2 == cost%2:
                color[dst] = 0
            else:
                color[dst] = 1
            dist[dst] = dist[src] + cost
            dq.append((dist[dst], dst))
    print(*color, sep='\n') main
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
from collections import deque
#======================================================#
def main():
    n = II()
    graph = [[] for _ in range(n)]
    for i in range(n-1):
        u,v,w = MII()
        graph[u-1].append((w, v-1))
        graph[v-1].append((w, u-1))
    dq = deque()
    color = [-1]*n
    dist = [-1]*n
    dq.append((0,0))
    color[0] = 0
    dist[0] = 0
    while dq:
        prev_cost, src = dq.popleft()
        for cost, dst in graph[src]:
            if dist[dst] != -1:
                continue
            if prev_cost%2 == cost%2:
                color[dst] = 0
            else:
                color[dst] = 1
            dist[dst] = dist[src] + cost
            dq.append((dist[dst], dst))
    print(*color, sep='\n')

if __name__ == '__main__':
    main()