from collections import deque

def nearlist(N, LIST):  # 隣接リスト
    NEAR = [set([]) for _ in range(N)]
    DIST = {}
    for a, b, c in LIST:
        NEAR[a - 1].add(b - 1)
        NEAR[b - 1].add(a - 1)
        DIST[(a - 1, b - 1)], DIST[(b - 1, a - 1)] = c, c
    return NEAR, DIST


def bfs(NEAR, N):  # 幅優先探索  # キュー
    ANS = [-1 for _ in range(N)]
    ANS[0] = 0
    que, frag = deque([0]), set([0])

    while len(que) > 0:
        q = que.popleft()
        for i in NEAR[q]:  # 移動先の候補
            if i in frag:  # 処理済みか否か
                continue
            if dist[(q, i)] % 2 == 0:
                ANS[i] = ANS[q]
            elif dist[(q, i)] % 2 == 1:
                ANS[i] = -ANS[q] + 1
            que.append(i), frag.add(i)
    return ANS


n = int(input())
uvw = [list(map(int, input().split())) for _ in range(n - 1)]

near, dist = nearlist(n, uvw)
ans = bfs(near, n)
print(*ans, sep='\n') from collections import deque def nearlist(N, LIST):  # 隣接リスト
    NEAR = [set([]) for _ in range(N)]
    DIST = {}
    for a, b, c in LIST:
        NEAR[a - 1].add(b - 1)
        NEAR[b - 1].add(a - 1)
        DIST[(a - 1, b - 1)], DIST[(b - 1, a - 1)] = c, c
    return NEAR, DIST nearlist set([]) for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) set([]) set [] NEAR = [set([]) for _ in range(N)] NEAR [set([]) for _ in range(N)] DIST = {} DIST {} for a, b, c in LIST:
        NEAR[a - 1].add(b - 1)
        NEAR[b - 1].add(a - 1)
        DIST[(a - 1, b - 1)], DIST[(b - 1, a - 1)] = c, c
     a b c LIST NEAR[a - 1].add(b - 1) [a - 1].add [a - 1] NEAR a - 1 a 1 add b - 1 b 1 NEAR[b - 1].add(a - 1) [b - 1].add [b - 1] NEAR b - 1 b 1 add a - 1 a 1 DIST[(a - 1, b - 1)], DIST[(b - 1, a - 1)] = c, c DIST[(a - 1, b - 1)] DIST (a - 1, b - 1) a - 1 a 1 b - 1 b 1 c DIST[(b - 1, a - 1)] DIST (b - 1, a - 1) b - 1 b 1 a - 1 a 1 c return NEAR, DIST return NEAR, DIST NEAR DIST N N LIST LIST def bfs(NEAR, N):  # 幅優先探索  # キュー
    ANS = [-1 for _ in range(N)]
    ANS[0] = 0
    que, frag = deque([0]), set([0])

    while len(que) > 0:
        q = que.popleft()
        for i in NEAR[q]:  # 移動先の候補
            if i in frag:  # 処理済みか否か
                continue
            if dist[(q, i)] % 2 == 0:
                ANS[i] = ANS[q]
            elif dist[(q, i)] % 2 == 1:
                ANS[i] = -ANS[q] + 1
            que.append(i), frag.add(i)
    return ANS bfs -1 for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) -1 ANS = [-1 for _ in range(N)] ANS [-1 for _ in range(N)] ANS[0] = 0 ANS[0] ANS 0 0 que, frag = deque([0]), set([0]) que deque([0]) deque [0] 0 frag set([0]) set [0] 0 while len(que) > 0:
        q = que.popleft()
        for i in NEAR[q]:  # 移動先の候補
            if i in frag:  # 処理済みか否か
                continue
            if dist[(q, i)] % 2 == 0:
                ANS[i] = ANS[q]
            elif dist[(q, i)] % 2 == 1:
                ANS[i] = -ANS[q] + 1
            que.append(i), frag.add(i)
     len(que) > 0 len(que) len que 0 q = que.popleft() q que.popleft() que.popleft que popleft for i in NEAR[q]:  # 移動先の候補
            if i in frag:  # 処理済みか否か
                continue
            if dist[(q, i)] % 2 == 0:
                ANS[i] = ANS[q]
            elif dist[(q, i)] % 2 == 1:
                ANS[i] = -ANS[q] + 1
            que.append(i), frag.add(i)
     i NEAR[q] NEAR q if i in frag:  # 処理済みか否か
                continue
             i in frag i frag continue if dist[(q, i)] % 2 == 0:
                ANS[i] = ANS[q]
            elif dist[(q, i)] % 2 == 1:
                ANS[i] = -ANS[q] + 1
             dist[(q, i)] % 2 == 0 dist[(q, i)] % 2 dist[(q, i)] dist (q, i) q i 2 0 ANS[i] = ANS[q] ANS[i] ANS i ANS[q] ANS q elif dist[(q, i)] % 2 == 1:
                ANS[i] = -ANS[q] + 1
             dist[(q, i)] % 2 == 1 dist[(q, i)] % 2 dist[(q, i)] dist (q, i) q i 2 1 ANS[i] = -ANS[q] + 1 ANS[i] ANS i -ANS[q] + 1 -ANS[q] ANS[q] ANS q 1 que.append(i) que.append que append i frag.add(i) frag.add frag add i return ANS ANS NEAR NEAR N N n = int(input()) n int(input()) int input() input list(map(int, input().split())) for _ in range(n - 1) for _ in range(n - 1) _ range(n - 1) range n - 1 n 1 for _ in range(n - 1) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split uvw = [list(map(int, input().split())) for _ in range(n - 1)] uvw [list(map(int, input().split())) for _ in range(n - 1)] near, dist = nearlist(n, uvw) near nearlist(n, uvw) nearlist n uvw dist ans = bfs(near, n) ans bfs(near, n) bfs near n print(*ans, sep='\n') print *ans ans sep='\n' sep '\n' n = int(input()) int(input()) n ans = bfs(near, n) bfs(near, n) ans uvw = [list(map(int, input().split())) for _ in range(n - 1)] [list(map(int, input().split())) for _ in range(n - 1)] uvw def nearlist(N, LIST):  # 隣接リスト
    NEAR = [set([]) for _ in range(N)]
    DIST = {}
    for a, b, c in LIST:
        NEAR[a - 1].add(b - 1)
        NEAR[b - 1].add(a - 1)
        DIST[(a - 1, b - 1)], DIST[(b - 1, a - 1)] = c, c
    return NEAR, DIST def nearlist(N, LIST):  # 隣接リスト
    NEAR = [set([]) for _ in range(N)]
    DIST = {}
    for a, b, c in LIST:
        NEAR[a - 1].add(b - 1)
        NEAR[b - 1].add(a - 1)
        DIST[(a - 1, b - 1)], DIST[(b - 1, a - 1)] = c, c
    return NEAR, DIST nearlist dist = nearlist(n, uvw) nearlist(n, uvw) dist near, dist = nearlist(n, uvw) nearlist(n, uvw) near def bfs(NEAR, N):  # 幅優先探索  # キュー
    ANS = [-1 for _ in range(N)]
    ANS[0] = 0
    que, frag = deque([0]), set([0])

    while len(que) > 0:
        q = que.popleft()
        for i in NEAR[q]:  # 移動先の候補
            if i in frag:  # 処理済みか否か
                continue
            if dist[(q, i)] % 2 == 0:
                ANS[i] = ANS[q]
            elif dist[(q, i)] % 2 == 1:
                ANS[i] = -ANS[q] + 1
            que.append(i), frag.add(i)
    return ANS def bfs(NEAR, N):  # 幅優先探索  # キュー
    ANS = [-1 for _ in range(N)]
    ANS[0] = 0
    que, frag = deque([0]), set([0])

    while len(que) > 0:
        q = que.popleft()
        for i in NEAR[q]:  # 移動先の候補
            if i in frag:  # 処理済みか否か
                continue
            if dist[(q, i)] % 2 == 0:
                ANS[i] = ANS[q]
            elif dist[(q, i)] % 2 == 1:
                ANS[i] = -ANS[q] + 1
            que.append(i), frag.add(i)
    return ANS bfs
from collections import deque

def nearlist(N, LIST):  # 隣接リスト
    NEAR = [set([]) for _ in range(N)]
    DIST = {}
    for a, b, c in LIST:
        NEAR[a - 1].add(b - 1)
        NEAR[b - 1].add(a - 1)
        DIST[(a - 1, b - 1)], DIST[(b - 1, a - 1)] = c, c
    return NEAR, DIST


def bfs(NEAR, N):  # 幅優先探索  # キュー
    ANS = [-1 for _ in range(N)]
    ANS[0] = 0
    que, frag = deque([0]), set([0])

    while len(que) > 0:
        q = que.popleft()
        for i in NEAR[q]:  # 移動先の候補
            if i in frag:  # 処理済みか否か
                continue
            if dist[(q, i)] % 2 == 0:
                ANS[i] = ANS[q]
            elif dist[(q, i)] % 2 == 1:
                ANS[i] = -ANS[q] + 1
            que.append(i), frag.add(i)
    return ANS


n = int(input())
uvw = [list(map(int, input().split())) for _ in range(n - 1)]

near, dist = nearlist(n, uvw)
ans = bfs(near, n)
print(*ans, sep='\n')
