N = int(input())
u, v, w = [0]*(N-1), [0]*(N-1), [0]*(N-1)
n = [-1] * N
# n[][0] 色　n[][1] 連結先一覧リスト n[][2] mod2 
for i in range(N):
    n[i] = [0]*4
    n[i][1] = []
    n[i][2] = []

for i in range(N-1):
    u[i], v[i], w[i] = list(map(int, input().split()))
    n[u[i]-1][1].append(v[i]-1)
    n[v[i]-1][1].append(u[i]-1)
    n[u[i]-1][2].append(w[i]%2)
    n[v[i]-1][2].append(w[i]%2)

stack = [u[0]-1]

while True:
    num = stack.pop()
    n[num][3] = 1
    for i in range(len(n[num][1])):
        if n[n[num][1][i]][3] == 0:
            stack.append(n[num][1][i])
            if n[num][2][i] == 0:
                n[n[num][1][i]][0] = n[num][0]
            else:
                n[n[num][1][i]][0] = -1 * n[num][0] + 1
    if len(stack) == 0:
        break

for i in n:
    print(i[0]) N = int(input()) N int(input()) int input() input u, v, w = [0]*(N-1), [0]*(N-1), [0]*(N-1) u [0]*(N-1) [0] 0 N-1 N 1 v [0]*(N-1) [0] 0 N-1 N 1 w [0]*(N-1) [0] 0 N-1 N 1 n = [-1] * N n [-1] * N [-1] -1 N for i in range(N):
    n[i] = [0]*4
    n[i][1] = []
    n[i][2] = [] i range(N) range N n[i] = [0]*4 n[i] n i [0]*4 [0] 0 4 n[i][1] = [] n[i][1] [i] n i 1 [] n[i][2] = [] n[i][2] [i] n i 2 [] for i in range(N-1):
    u[i], v[i], w[i] = list(map(int, input().split()))
    n[u[i]-1][1].append(v[i]-1)
    n[v[i]-1][1].append(u[i]-1)
    n[u[i]-1][2].append(w[i]%2)
    n[v[i]-1][2].append(w[i]%2) i range(N-1) range N-1 N 1 u[i], v[i], w[i] = list(map(int, input().split())) u[i] u i list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split v[i] v i w[i] w i n[u[i]-1][1].append(v[i]-1) [1].append [1] [u[i]-1] n u[i]-1 u[i] u i 1 1 append v[i]-1 v[i] v i 1 n[v[i]-1][1].append(u[i]-1) [1].append [1] [v[i]-1] n v[i]-1 v[i] v i 1 1 append u[i]-1 u[i] u i 1 n[u[i]-1][2].append(w[i]%2) [2].append [2] [u[i]-1] n u[i]-1 u[i] u i 1 2 append w[i]%2 w[i] w i 2 n[v[i]-1][2].append(w[i]%2) [2].append [2] [v[i]-1] n v[i]-1 v[i] v i 1 2 append w[i]%2 w[i] w i 2 stack = [u[0]-1] stack [u[0]-1] u[0]-1 u[0] u 0 1 while True:
    num = stack.pop()
    n[num][3] = 1
    for i in range(len(n[num][1])):
        if n[n[num][1][i]][3] == 0:
            stack.append(n[num][1][i])
            if n[num][2][i] == 0:
                n[n[num][1][i]][0] = n[num][0]
            else:
                n[n[num][1][i]][0] = -1 * n[num][0] + 1
    if len(stack) == 0:
        break True num = stack.pop() num stack.pop() stack.pop stack pop n[num][3] = 1 n[num][3] [num] n num 3 1 for i in range(len(n[num][1])):
        if n[n[num][1][i]][3] == 0:
            stack.append(n[num][1][i])
            if n[num][2][i] == 0:
                n[n[num][1][i]][0] = n[num][0]
            else:
                n[n[num][1][i]][0] = -1 * n[num][0] + 1
     i range(len(n[num][1])) range len(n[num][1]) len n[num][1] [num] n num 1 if n[n[num][1][i]][3] == 0:
            stack.append(n[num][1][i])
            if n[num][2][i] == 0:
                n[n[num][1][i]][0] = n[num][0]
            else:
                n[n[num][1][i]][0] = -1 * n[num][0] + 1
     n[n[num][1][i]][3] == 0 n[n[num][1][i]][3] [n[num][1][i]] n n[num][1][i] [1] [num] n num 1 i 3 0 stack.append(n[num][1][i]) stack.append stack append n[num][1][i] [1] [num] n num 1 i if n[num][2][i] == 0:
                n[n[num][1][i]][0] = n[num][0]
            else:
                n[n[num][1][i]][0] = -1 * n[num][0] + 1
     n[num][2][i] == 0 n[num][2][i] [2] [num] n num 2 i 0 n[n[num][1][i]][0] = n[num][0] n[n[num][1][i]][0] [n[num][1][i]] n n[num][1][i] [1] [num] n num 1 i 0 n[num][0] [num] n num 0 n[n[num][1][i]][0] = -1 * n[num][0] + 1 n[n[num][1][i]][0] [n[num][1][i]] n n[num][1][i] [1] [num] n num 1 i 0 -1 * n[num][0] + 1 -1 * n[num][0] -1 n[num][0] [num] n num 0 1 if len(stack) == 0:
        break len(stack) == 0 len(stack) len stack 0 break for i in n:
    print(i[0]) i n print(i[0]) print i[0] i 0 stack = [u[0]-1] [u[0]-1] stack w = [0]*(N-1), [0]*(N-1), [0]*(N-1) [0]*(N-1) w N = int(input()) int(input()) N v, w = [0]*(N-1), [0]*(N-1), [0]*(N-1) [0]*(N-1) v num = stack.pop() stack.pop() num u, v, w = [0]*(N-1), [0]*(N-1), [0]*(N-1) [0]*(N-1) u n = [-1] * N [-1] * N n
N = int(input())
u, v, w = [0]*(N-1), [0]*(N-1), [0]*(N-1)
n = [-1] * N
# n[][0] 色　n[][1] 連結先一覧リスト n[][2] mod2 
for i in range(N):
    n[i] = [0]*4
    n[i][1] = []
    n[i][2] = []

for i in range(N-1):
    u[i], v[i], w[i] = list(map(int, input().split()))
    n[u[i]-1][1].append(v[i]-1)
    n[v[i]-1][1].append(u[i]-1)
    n[u[i]-1][2].append(w[i]%2)
    n[v[i]-1][2].append(w[i]%2)

stack = [u[0]-1]

while True:
    num = stack.pop()
    n[num][3] = 1
    for i in range(len(n[num][1])):
        if n[n[num][1][i]][3] == 0:
            stack.append(n[num][1][i])
            if n[num][2][i] == 0:
                n[n[num][1][i]][0] = n[num][0]
            else:
                n[n[num][1][i]][0] = -1 * n[num][0] + 1
    if len(stack) == 0:
        break

for i in n:
    print(i[0])