# coding: utf-8
import sys

# from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
printout = sys.stdout.write
sprint = sys.stdout.flush
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
#import math
# from itertools import product, accumulate, combinations, product
#import bisect
# import numpy as np
# from copy import deepcopy
from collections import deque
# from decimal import Decimal
# from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 998244353


def intread():
    return int(sysread())
def mapline(t=int):
    return map(t, sysread().split())
def mapread(t=int):
    return map(t, read().split())

def dfs(c, num, to, cols):
    for n, nw in to[c]:
        if cols[n] == -1:
            y = (num + nw) % 2
            cols[n] = (num + nw) % 2
            dfs(n, y, to, cols)

def run():
    N = intread()
    to = [[] for _ in range(N+1)]
    for _ in range(N-1):
        u, v, w = mapline()
        to[u].append((v, w))
        to[v].append((u, w))
    cols = [-1] * (N+1)
    cols[1] = 0
    dfs(1, 0, to, cols)

    for x in cols[1:]:
        print(x)

if __name__ == "__main__":
    run() import sys sys sysread = sys.stdin.buffer.readline sysread sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read printout = sys.stdout.write printout sys.stdout.write sys.stdout sys stdout write sprint = sys.stdout.flush sprint sys.stdout.flush sys.stdout sys stdout flush sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 from collections import deque INF = 1 << 50 INF 1 << 50 1 50 EPS = 1e-8 EPS 1e-8 mod = 998244353 mod 998244353 def intread():
    return int(sysread()) intread return int(sysread()) int(sysread()) int sysread() sysread def mapline(t=int):
    return map(t, sysread().split()) mapline return map(t, sysread().split()) map(t, sysread().split()) map t sysread().split() ().split () sysread split t=int t int def mapread(t=int):
    return map(t, read().split()) mapread return map(t, read().split()) map(t, read().split()) map t read().split() ().split () read split t=int t int def dfs(c, num, to, cols):
    for n, nw in to[c]:
        if cols[n] == -1:
            y = (num + nw) % 2
            cols[n] = (num + nw) % 2
            dfs(n, y, to, cols) dfs for n, nw in to[c]:
        if cols[n] == -1:
            y = (num + nw) % 2
            cols[n] = (num + nw) % 2
            dfs(n, y, to, cols) n nw to[c] to c if cols[n] == -1:
            y = (num + nw) % 2
            cols[n] = (num + nw) % 2
            dfs(n, y, to, cols) cols[n] == -1 cols[n] cols n -1 y = (num + nw) % 2 y (num + nw) % 2 num + nw num nw 2 cols[n] = (num + nw) % 2 cols[n] cols n (num + nw) % 2 num + nw num nw 2 dfs(n, y, to, cols) dfs n y to cols c c num num to to cols cols def run():
    N = intread()
    to = [[] for _ in range(N+1)]
    for _ in range(N-1):
        u, v, w = mapline()
        to[u].append((v, w))
        to[v].append((u, w))
    cols = [-1] * (N+1)
    cols[1] = 0
    dfs(1, 0, to, cols)

    for x in cols[1:]:
        print(x) run N = intread() N intread() intread [] for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) [] to = [[] for _ in range(N+1)] to [[] for _ in range(N+1)] for _ in range(N-1):
        u, v, w = mapline()
        to[u].append((v, w))
        to[v].append((u, w))
     _ range(N-1) range N-1 N 1 u, v, w = mapline() u mapline() mapline v w to[u].append((v, w)) [u].append [u] to u append (v, w) v w to[v].append((u, w)) [v].append [v] to v append (u, w) u w cols = [-1] * (N+1) cols [-1] * (N+1) [-1] -1 N+1 N 1 cols[1] = 0 cols[1] cols 1 0 dfs(1, 0, to, cols) dfs 1 0 to cols for x in cols[1:]:
        print(x) x cols[1:] cols 1: 1 print(x) print x if __name__ == "__main__":
    run() __name__ == "__main__" __name__ "__main__" run() run def intread():
    return int(sysread()) def intread():
    return int(sysread()) intread def dfs(c, num, to, cols):
    for n, nw in to[c]:
        if cols[n] == -1:
            y = (num + nw) % 2
            cols[n] = (num + nw) % 2
            dfs(n, y, to, cols) def dfs(c, num, to, cols):
    for n, nw in to[c]:
        if cols[n] == -1:
            y = (num + nw) % 2
            cols[n] = (num + nw) % 2
            dfs(n, y, to, cols) dfs printout = sys.stdout.write sys.stdout.write printout sprint = sys.stdout.flush sys.stdout.flush sprint sysread = sys.stdin.buffer.readline sys.stdin.buffer.readline sysread mod = 998244353 998244353 mod read = sys.stdin.buffer.read sys.stdin.buffer.read read INF = 1 << 50 1 << 50 INF EPS = 1e-8 1e-8 EPS def run():
    N = intread()
    to = [[] for _ in range(N+1)]
    for _ in range(N-1):
        u, v, w = mapline()
        to[u].append((v, w))
        to[v].append((u, w))
    cols = [-1] * (N+1)
    cols[1] = 0
    dfs(1, 0, to, cols)

    for x in cols[1:]:
        print(x) def run():
    N = intread()
    to = [[] for _ in range(N+1)]
    for _ in range(N-1):
        u, v, w = mapline()
        to[u].append((v, w))
        to[v].append((u, w))
    cols = [-1] * (N+1)
    cols[1] = 0
    dfs(1, 0, to, cols)

    for x in cols[1:]:
        print(x) run def mapline(t=int):
    return map(t, sysread().split()) def mapline(t=int):
    return map(t, sysread().split()) mapline def mapread(t=int):
    return map(t, read().split()) def mapread(t=int):
    return map(t, read().split()) mapread
# coding: utf-8
import sys

# from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
printout = sys.stdout.write
sprint = sys.stdout.flush
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
#import math
# from itertools import product, accumulate, combinations, product
#import bisect
# import numpy as np
# from copy import deepcopy
from collections import deque
# from decimal import Decimal
# from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 998244353


def intread():
    return int(sysread())
def mapline(t=int):
    return map(t, sysread().split())
def mapread(t=int):
    return map(t, read().split())

def dfs(c, num, to, cols):
    for n, nw in to[c]:
        if cols[n] == -1:
            y = (num + nw) % 2
            cols[n] = (num + nw) % 2
            dfs(n, y, to, cols)

def run():
    N = intread()
    to = [[] for _ in range(N+1)]
    for _ in range(N-1):
        u, v, w = mapline()
        to[u].append((v, w))
        to[v].append((u, w))
    cols = [-1] * (N+1)
    cols[1] = 0
    dfs(1, 0, to, cols)

    for x in cols[1:]:
        print(x)

if __name__ == "__main__":
    run()
