import sys
sys.setrecursionlimit(10 ** 6)
N = int(input())
uvw = [list(map(int, input().split())) for i in range(N - 1)]
R = [-1] * N
Q = [[] for i in range(N)]
for i in range(N - 1):
    Q[uvw[i][0] - 1].append([uvw[i][1], uvw[i][2]])
    Q[uvw[i][1] - 1].append([uvw[i][0], uvw[i][2]])

def func(i, s, d, l):
    
    if R[i] != -1:
        return

    if R[i] == -1:
        if l %2 == 0:
            R[i] = s
        else:
            R[i] = d
            tmp = s
            s = d
            d = tmp
    for j in range(len(Q[i])):
        func(Q[i][j][0] - 1, s, d, Q[i][j][1])

func(uvw[0][0] - 1, 0, 1, 0)
for i in range(len(R)):
    print(R[i]) import sys sys sys.setrecursionlimit(10 ** 6) sys.setrecursionlimit sys setrecursionlimit 10 ** 6 10 6 N = int(input()) N int(input()) int input() input list(map(int, input().split())) 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) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split uvw = [list(map(int, input().split())) for i in range(N - 1)] uvw [list(map(int, input().split())) for i in range(N - 1)] R = [-1] * N R [-1] * N [-1] -1 N [] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [] Q = [[] for i in range(N)] Q [[] for i in range(N)] for i in range(N - 1):
    Q[uvw[i][0] - 1].append([uvw[i][1], uvw[i][2]])
    Q[uvw[i][1] - 1].append([uvw[i][0], uvw[i][2]]) i range(N - 1) range N - 1 N 1 Q[uvw[i][0] - 1].append([uvw[i][1], uvw[i][2]]) [uvw[i][0] - 1].append [uvw[i][0] - 1] Q uvw[i][0] - 1 uvw[i][0] [i] uvw i 0 1 append [uvw[i][1], uvw[i][2]] uvw[i][1] [i] uvw i 1 uvw[i][2] [i] uvw i 2 Q[uvw[i][1] - 1].append([uvw[i][0], uvw[i][2]]) [uvw[i][1] - 1].append [uvw[i][1] - 1] Q uvw[i][1] - 1 uvw[i][1] [i] uvw i 1 1 append [uvw[i][0], uvw[i][2]] uvw[i][0] [i] uvw i 0 uvw[i][2] [i] uvw i 2 def func(i, s, d, l):
    
    if R[i] != -1:
        return

    if R[i] == -1:
        if l %2 == 0:
            R[i] = s
        else:
            R[i] = d
            tmp = s
            s = d
            d = tmp
    for j in range(len(Q[i])):
        func(Q[i][j][0] - 1, s, d, Q[i][j][1]) func if R[i] != -1:
        return

     R[i] != -1 R[i] R i -1 return if R[i] == -1:
        if l %2 == 0:
            R[i] = s
        else:
            R[i] = d
            tmp = s
            s = d
            d = tmp
     R[i] == -1 R[i] R i -1 if l %2 == 0:
            R[i] = s
        else:
            R[i] = d
            tmp = s
            s = d
            d = tmp
     l %2 == 0 l %2 l 2 0 R[i] = s R[i] R i s R[i] = d R[i] R i d tmp = s tmp s s = d s d d = tmp d tmp for j in range(len(Q[i])):
        func(Q[i][j][0] - 1, s, d, Q[i][j][1]) j range(len(Q[i])) range len(Q[i]) len Q[i] Q i func(Q[i][j][0] - 1, s, d, Q[i][j][1]) func Q[i][j][0] - 1 Q[i][j][0] [j] [i] Q i j 0 1 s d Q[i][j][1] [j] [i] Q i j 1 i i s s d d l l func(uvw[0][0] - 1, 0, 1, 0) func uvw[0][0] - 1 uvw[0][0] [0] uvw 0 0 1 0 1 0 for i in range(len(R)):
    print(R[i]) i range(len(R)) range len(R) len R print(R[i]) print R[i] R i R = [-1] * N [-1] * N R N = int(input()) int(input()) N Q = [[] for i in range(N)] [[] for i in range(N)] Q uvw = [list(map(int, input().split())) for i in range(N - 1)] [list(map(int, input().split())) for i in range(N - 1)] uvw def func(i, s, d, l):
    
    if R[i] != -1:
        return

    if R[i] == -1:
        if l %2 == 0:
            R[i] = s
        else:
            R[i] = d
            tmp = s
            s = d
            d = tmp
    for j in range(len(Q[i])):
        func(Q[i][j][0] - 1, s, d, Q[i][j][1]) def func(i, s, d, l):
    
    if R[i] != -1:
        return

    if R[i] == -1:
        if l %2 == 0:
            R[i] = s
        else:
            R[i] = d
            tmp = s
            s = d
            d = tmp
    for j in range(len(Q[i])):
        func(Q[i][j][0] - 1, s, d, Q[i][j][1]) func
import sys
sys.setrecursionlimit(10 ** 6)
N = int(input())
uvw = [list(map(int, input().split())) for i in range(N - 1)]
R = [-1] * N
Q = [[] for i in range(N)]
for i in range(N - 1):
    Q[uvw[i][0] - 1].append([uvw[i][1], uvw[i][2]])
    Q[uvw[i][1] - 1].append([uvw[i][0], uvw[i][2]])

def func(i, s, d, l):
    
    if R[i] != -1:
        return

    if R[i] == -1:
        if l %2 == 0:
            R[i] = s
        else:
            R[i] = d
            tmp = s
            s = d
            d = tmp
    for j in range(len(Q[i])):
        func(Q[i][j][0] - 1, s, d, Q[i][j][1])

func(uvw[0][0] - 1, 0, 1, 0)
for i in range(len(R)):
    print(R[i])