from collections import defaultdict


N, *UVW = map(int, open(0).read().split())
g = defaultdict(set)

ans = [0] * N
for u, v, w in zip(*[iter(UVW)] * 3):
    u -= 1
    v -= 1
    g[u].add((v, w))
    g[v].add((u, w))
visited = {0}
stack = [0]
while stack:
    v = stack.pop()
    for nv, nw in g[v]:
        if nv in visited:
            continue
        if nw % 2:
            ans[nv] = ans[v] ^ 1
        else:
            ans[nv] = ans[v]
        stack.append(nv)
        visited.add(v)
print("\n".join(map(str, ans))) from collections import defaultdict N, *UVW = map(int, open(0).read().split()) N map(int, open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split *UVW UVW g = defaultdict(set) g defaultdict(set) defaultdict set ans = [0] * N ans [0] * N [0] 0 N for u, v, w in zip(*[iter(UVW)] * 3):
    u -= 1
    v -= 1
    g[u].add((v, w))
    g[v].add((u, w)) u v w zip(*[iter(UVW)] * 3) zip *[iter(UVW)] * 3 [iter(UVW)] * 3 [iter(UVW)] iter(UVW) iter UVW 3 u -= 1 u 1 v -= 1 v 1 g[u].add((v, w)) [u].add [u] g u add (v, w) v w g[v].add((u, w)) [v].add [v] g v add (u, w) u w visited = {0} visited {0} stack = [0] stack [0] 0 while stack:
    v = stack.pop()
    for nv, nw in g[v]:
        if nv in visited:
            continue
        if nw % 2:
            ans[nv] = ans[v] ^ 1
        else:
            ans[nv] = ans[v]
        stack.append(nv)
        visited.add(v) stack v = stack.pop() v stack.pop() stack.pop stack pop for nv, nw in g[v]:
        if nv in visited:
            continue
        if nw % 2:
            ans[nv] = ans[v] ^ 1
        else:
            ans[nv] = ans[v]
        stack.append(nv)
        visited.add(v) nv nw g[v] g v if nv in visited:
            continue
         nv in visited nv visited continue if nw % 2:
            ans[nv] = ans[v] ^ 1
        else:
            ans[nv] = ans[v]
         nw % 2 nw 2 ans[nv] = ans[v] ^ 1 ans[nv] ans nv ans[v] ^ 1 ans[v] ans v 1 ans[nv] = ans[v] ans[nv] ans nv ans[v] ans v stack.append(nv) stack.append stack append nv visited.add(v) visited.add visited add v print("\n".join(map(str, ans))) print "\n".join(map(str, ans)) "\n".join "\n" join map(str, ans) map str ans u -= 1 1 u v = stack.pop() stack.pop() v stack = [0] [0] stack g = defaultdict(set) defaultdict(set) g ans = [0] * N [0] * N ans v -= 1 1 v N, *UVW = map(int, open(0).read().split()) map(int, open(0).read().split()) N visited = {0} {0} visited
from collections import defaultdict


N, *UVW = map(int, open(0).read().split())
g = defaultdict(set)

ans = [0] * N
for u, v, w in zip(*[iter(UVW)] * 3):
    u -= 1
    v -= 1
    g[u].add((v, w))
    g[v].add((u, w))
visited = {0}
stack = [0]
while stack:
    v = stack.pop()
    for nv, nw in g[v]:
        if nv in visited:
            continue
        if nw % 2:
            ans[nv] = ans[v] ^ 1
        else:
            ans[nv] = ans[v]
        stack.append(nv)
        visited.add(v)
print("\n".join(map(str, ans)))
