import heapq



N = int(eval(input()))

graph = {i:[] for i in range(1, N+1)}

route = [10**20 for i in range(N+1)]

visited = [False for i in range(N+1)]



for i in range(N-1):

    u, v, w = list(map(int, input().split()))

    graph[u].append((v, w))

    graph[v].append((u, w))



for key, value in list(graph.items()):

    if len(value):

        start = key

        route[start] = 0

        visited[start] = True

        q = []

        for v, w in value:

            route[v] = min(route[v], w)

            heapq.heappush(q, (w, v))

        break



while len(q):

    w, v = heapq.heappop(q)

    if not visited[v]:

        visited[v] = True

        for u, c in graph[v]:

            if route[u] > route[v] + c:

                route[u] = route[v] + c

                heapq.heappush(q, (c, u))



for n in route[1:]:

    if n % 2:

        print('1')

    else:

        print('0')
import sys

from heapq import heappush, heappop, heapify



input = sys.stdin.readline



def main():

    INF = float('inf')

    N = int(eval(input()))

    dist = [INF] * N

    visited = [False] * N

    

    E = [[] for i in range(N)]

    V = None

    

    for i in range(N-1):

        u, v, w = list(map(int, input().split()))

        E[u-1].append((v-1, w))

        E[v-1].append((u-1, w))

        

        if V is None: V = u-1

    

    q = E[V]

    heapify(q)

    dist[V] = 0

    visited[V] = True

    

    while q:

        v, w = heappop(q)

    

        if visited[v]: continue

    

        visited[v] = True

        dist[v] = w

        

        for u, c in E[v]:

            if visited[u] or dist[u] <= w+c: continue

            heappush(q, (u, w+c))

            

    for d in dist:

        if d % 2: print((0))

        else: print((1))



if __name__ == '__main__':

    main()
import heapq

N = int(eval(input()))
graph = {i: [] for i in range(1, N + 1)}
route = [10**20 for i in range(N + 1)]
visited = [False for i in range(N + 1)]
for i in range(N - 1):
    u, v, w = list(map(int, input().split()))
    graph[u].append((v, w))
    graph[v].append((u, w))
for key, value in list(graph.items()):
    if len(value):
        start = key
        route[start] = 0
        visited[start] = True
        q = []
        for v, w in value:
            route[v] = min(route[v], w)
            heapq.heappush(q, (w, v))
        break
while len(q):
    w, v = heapq.heappop(q)
    if not visited[v]:
        visited[v] = True
        for u, c in graph[v]:
            if route[u] > route[v] + c:
                route[u] = route[v] + c
                heapq.heappush(q, (c, u))
for n in route[1:]:
    if n % 2:
        print("1")
    else:
        print("0")

import sys
from heapq import heappush, heappop, heapify

input = sys.stdin.readline


def main():
    INF = float("inf")
    N = int(eval(input()))
    dist = [INF] * N
    visited = [False] * N
    E = [[] for i in range(N)]
    V = None
    for i in range(N - 1):
        u, v, w = list(map(int, input().split()))
        E[u - 1].append((v - 1, w))
        E[v - 1].append((u - 1, w))
        if V is None:
            V = u - 1
    q = E[V]
    heapify(q)
    dist[V] = 0
    visited[V] = True
    while q:
        v, w = heappop(q)
        if visited[v]:
            continue
        visited[v] = True
        dist[v] = w
        for u, c in E[v]:
            if visited[u] or dist[u] <= w + c:
                continue
            heappush(q, (u, w + c))
    for d in dist:
        if d % 2:
            print((0))
        else:
            print((1))


if __name__ == "__main__":
    main()

-import heapq +import sys +from heapq import heappush, heappop, heapify -N = int(eval(input())) -graph = {i: [] for i in range(1, N + 1)} -route = [10**20 for i in range(N + 1)] -visited = [False for i in range(N + 1)] -for i in range(N - 1): -    u, v, w = list(map(int, input().split())) -    graph[u].append((v, w)) -    graph[v].append((u, w)) -for key, value in list(graph.items()): -    if len(value): -        start = key -        route[start] = 0 -        visited[start] = True -        q = [] -        for v, w in value: -            route[v] = min(route[v], w) -            heapq.heappush(q, (w, v)) -        break -while len(q): -    w, v = heapq.heappop(q) -    if not visited[v]: +input = sys.stdin.readline + + +def main(): +    INF = float("inf") +    N = int(eval(input())) +    dist = [INF] * N +    visited = [False] * N +    E = [[] for i in range(N)] +    V = None +    for i in range(N - 1): +        u, v, w = list(map(int, input().split())) +        E[u - 1].append((v - 1, w)) +        E[v - 1].append((u - 1, w)) +        if V is None: +            V = u - 1 +    q = E[V] +    heapify(q) +    dist[V] = 0 +    visited[V] = True +    while q: +        v, w = heappop(q) +        if visited[v]: +            continue -        for u, c in graph[v]: -            if route[u] > route[v] + c: -                route[u] = route[v] + c -                heapq.heappush(q, (c, u)) -for n in route[1:]: -    if n % 2: -        print("1") -    else: -        print("0") +        dist[v] = w +        for u, c in E[v]: +            if visited[u] or dist[u] <= w + c: +                continue +            heappush(q, (u, w + c)) +    for d in dist: +        if d % 2: +            print((0)) +        else: +            print((1)) + + +if __name__ == "__main__": +    main()