import sys
sys.setrecursionlimit(10**6)
n = int(input())
edge = [[] for _ in range(n)]

for i in range(n-1):
    a,b,c=map(int, input().split())
    edge[a-1].append([b-1,c])
    edge[b-1].append([a-1,c])
#任意の点から行ける偶数の距離で行けるところを同じ色で塗る。
col = [-1]*n
visited = [0]*n

def dfs(i,c):
    visited[i]=1
    col[i] = c
    for j in edge[i]:
        if not visited[j[0]]:
            if j[1]%2==0:
                dfs(j[0],c)
            else:
                dfs(j[0],-1*c)


def main():
    dfs(0,1)
    for i in range(n):
        print(max(col[i],0))



if __name__ == '__main__':
    main() import sys sys sys.setrecursionlimit(10**6) sys.setrecursionlimit sys setrecursionlimit 10**6 10 6 n = int(input()) n int(input()) int input() input [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] edge = [[] for _ in range(n)] edge [[] for _ in range(n)] for i in range(n-1):
    a,b,c=map(int, input().split())
    edge[a-1].append([b-1,c])
    edge[b-1].append([a-1,c])
#任意の点から行ける偶数の距離で行けるところを同じ色で塗る。 i range(n-1) range n-1 n 1 a,b,c=map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b c edge[a-1].append([b-1,c]) [a-1].append [a-1] edge a-1 a 1 append [b-1,c] b-1 b 1 c edge[b-1].append([a-1,c]) [b-1].append [b-1] edge b-1 b 1 append [a-1,c] a-1 a 1 c col = [-1]*n col [-1]*n [-1] -1 n visited = [0]*n visited [0]*n [0] 0 n def dfs(i,c):
    visited[i]=1
    col[i] = c
    for j in edge[i]:
        if not visited[j[0]]:
            if j[1]%2==0:
                dfs(j[0],c)
            else:
                dfs(j[0],-1*c) dfs visited[i]=1 visited[i] visited i 1 col[i] = c col[i] col i c for j in edge[i]:
        if not visited[j[0]]:
            if j[1]%2==0:
                dfs(j[0],c)
            else:
                dfs(j[0],-1*c) j edge[i] edge i if not visited[j[0]]:
            if j[1]%2==0:
                dfs(j[0],c)
            else:
                dfs(j[0],-1*c) not visited[j[0]] visited[j[0]] visited j[0] j 0 if j[1]%2==0:
                dfs(j[0],c)
            else:
                dfs(j[0],-1*c) j[1]%2==0 j[1]%2 j[1] j 1 2 0 dfs(j[0],c) dfs j[0] j 0 c dfs(j[0],-1*c) dfs j[0] j 0 -1*c -1 c i i c c def main():
    dfs(0,1)
    for i in range(n):
        print(max(col[i],0)) main dfs(0,1) dfs 0 1 for i in range(n):
        print(max(col[i],0)) i range(n) range n print(max(col[i],0)) print max(col[i],0) max col[i] col i 0 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main edge = [[] for _ in range(n)] [[] for _ in range(n)] edge c=map(int, input().split()) map(int, input().split()) c a,b,c=map(int, input().split()) map(int, input().split()) a visited = [0]*n [0]*n visited n = int(input()) int(input()) n def main():
    dfs(0,1)
    for i in range(n):
        print(max(col[i],0)) def main():
    dfs(0,1)
    for i in range(n):
        print(max(col[i],0)) main def dfs(i,c):
    visited[i]=1
    col[i] = c
    for j in edge[i]:
        if not visited[j[0]]:
            if j[1]%2==0:
                dfs(j[0],c)
            else:
                dfs(j[0],-1*c) def dfs(i,c):
    visited[i]=1
    col[i] = c
    for j in edge[i]:
        if not visited[j[0]]:
            if j[1]%2==0:
                dfs(j[0],c)
            else:
                dfs(j[0],-1*c) dfs b,c=map(int, input().split()) map(int, input().split()) b col = [-1]*n [-1]*n col
import sys
sys.setrecursionlimit(10**6)
n = int(input())
edge = [[] for _ in range(n)]

for i in range(n-1):
    a,b,c=map(int, input().split())
    edge[a-1].append([b-1,c])
    edge[b-1].append([a-1,c])
#任意の点から行ける偶数の距離で行けるところを同じ色で塗る。
col = [-1]*n
visited = [0]*n

def dfs(i,c):
    visited[i]=1
    col[i] = c
    for j in edge[i]:
        if not visited[j[0]]:
            if j[1]%2==0:
                dfs(j[0],c)
            else:
                dfs(j[0],-1*c)


def main():
    dfs(0,1)
    for i in range(n):
        print(max(col[i],0))



if __name__ == '__main__':
    main()
