# coding: utf-8
import sys
import copy

sys.setrecursionlimit(10 ** 9)


def dfs(seen, graph, i):
    for v, w in graph[i]: 
        if seen[v-1] != -1:
            continue
        seen[v-1] = abs((w % 2) - seen[i])
        dfs(seen, graph, v-1)
    

def main():
    n = int(input())
    graph = [[] for _ in range(n)]
    for _ in range(n-1):
        ui, vi, wi = map(int, input().split())
        graph[ui-1].append((vi, wi))
        graph[vi-1].append((ui, wi))
    
    seen = [-1 for _ in range(n)]
    seen[0] = 0
    for i in range(n-1):
        dfs(seen, graph, i)
        
    print(*seen, sep='\n')
        
main() import sys sys import copy copy sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 def dfs(seen, graph, i):
    for v, w in graph[i]: 
        if seen[v-1] != -1:
            continue
        seen[v-1] = abs((w % 2) - seen[i])
        dfs(seen, graph, v-1)
     dfs for v, w in graph[i]: 
        if seen[v-1] != -1:
            continue
        seen[v-1] = abs((w % 2) - seen[i])
        dfs(seen, graph, v-1)
     v w graph[i] graph i if seen[v-1] != -1:
            continue
         seen[v-1] != -1 seen[v-1] seen v-1 v 1 -1 continue seen[v-1] = abs((w % 2) - seen[i]) seen[v-1] seen v-1 v 1 abs((w % 2) - seen[i]) abs (w % 2) - seen[i] w % 2 w 2 seen[i] seen i dfs(seen, graph, v-1) dfs seen graph v-1 v 1 seen seen graph graph i i def main():
    n = int(input())
    graph = [[] for _ in range(n)]
    for _ in range(n-1):
        ui, vi, wi = map(int, input().split())
        graph[ui-1].append((vi, wi))
        graph[vi-1].append((ui, wi))
    
    seen = [-1 for _ in range(n)]
    seen[0] = 0
    for i in range(n-1):
        dfs(seen, graph, i)
        
    print(*seen, sep='\n')
         main 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) [] graph = [[] for _ in range(n)] graph [[] for _ in range(n)] for _ in range(n-1):
        ui, vi, wi = map(int, input().split())
        graph[ui-1].append((vi, wi))
        graph[vi-1].append((ui, wi))
    
     _ range(n-1) range n-1 n 1 ui, vi, wi = map(int, input().split()) ui map(int, input().split()) map int input().split() ().split () input split vi wi graph[ui-1].append((vi, wi)) [ui-1].append [ui-1] graph ui-1 ui 1 append (vi, wi) vi wi graph[vi-1].append((ui, wi)) [vi-1].append [vi-1] graph vi-1 vi 1 append (ui, wi) ui wi -1 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) -1 seen = [-1 for _ in range(n)] seen [-1 for _ in range(n)] seen[0] = 0 seen[0] seen 0 0 for i in range(n-1):
        dfs(seen, graph, i)
        
     i range(n-1) range n-1 n 1 dfs(seen, graph, i) dfs seen graph i print(*seen, sep='\n') print *seen seen sep='\n' sep '\n' main() main def dfs(seen, graph, i):
    for v, w in graph[i]: 
        if seen[v-1] != -1:
            continue
        seen[v-1] = abs((w % 2) - seen[i])
        dfs(seen, graph, v-1)
     def dfs(seen, graph, i):
    for v, w in graph[i]: 
        if seen[v-1] != -1:
            continue
        seen[v-1] = abs((w % 2) - seen[i])
        dfs(seen, graph, v-1)
     dfs def main():
    n = int(input())
    graph = [[] for _ in range(n)]
    for _ in range(n-1):
        ui, vi, wi = map(int, input().split())
        graph[ui-1].append((vi, wi))
        graph[vi-1].append((ui, wi))
    
    seen = [-1 for _ in range(n)]
    seen[0] = 0
    for i in range(n-1):
        dfs(seen, graph, i)
        
    print(*seen, sep='\n')
         def main():
    n = int(input())
    graph = [[] for _ in range(n)]
    for _ in range(n-1):
        ui, vi, wi = map(int, input().split())
        graph[ui-1].append((vi, wi))
        graph[vi-1].append((ui, wi))
    
    seen = [-1 for _ in range(n)]
    seen[0] = 0
    for i in range(n-1):
        dfs(seen, graph, i)
        
    print(*seen, sep='\n')
         main
# coding: utf-8
import sys
import copy

sys.setrecursionlimit(10 ** 9)


def dfs(seen, graph, i):
    for v, w in graph[i]: 
        if seen[v-1] != -1:
            continue
        seen[v-1] = abs((w % 2) - seen[i])
        dfs(seen, graph, v-1)
    

def main():
    n = int(input())
    graph = [[] for _ in range(n)]
    for _ in range(n-1):
        ui, vi, wi = map(int, input().split())
        graph[ui-1].append((vi, wi))
        graph[vi-1].append((ui, wi))
    
    seen = [-1 for _ in range(n)]
    seen[0] = 0
    for i in range(n-1):
        dfs(seen, graph, i)
        
    print(*seen, sep='\n')
        
main()
