from collections import defaultdict, deque
 
 
def bfs(start):
    q = deque([start])
    dist = [-1] * N
    dist[start] = 0
    while q:
        v = q.popleft()
        for nv, nw in g[v]:
            if dist[nv] >= 0:
                continue
            dist[nv] = (dist[v] + nw) % 2
            q.append(nv)
    return dist
 
 
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))
print("\n".join(map(str, bfs(0)))) from collections import defaultdict, deque def bfs(start):
    q = deque([start])
    dist = [-1] * N
    dist[start] = 0
    while q:
        v = q.popleft()
        for nv, nw in g[v]:
            if dist[nv] >= 0:
                continue
            dist[nv] = (dist[v] + nw) % 2
            q.append(nv)
    return dist
 
  bfs q = deque([start]) q deque([start]) deque [start] start dist = [-1] * N dist [-1] * N [-1] -1 N dist[start] = 0 dist[start] dist start 0 while q:
        v = q.popleft()
        for nv, nw in g[v]:
            if dist[nv] >= 0:
                continue
            dist[nv] = (dist[v] + nw) % 2
            q.append(nv)
     q v = q.popleft() v q.popleft() q.popleft q popleft for nv, nw in g[v]:
            if dist[nv] >= 0:
                continue
            dist[nv] = (dist[v] + nw) % 2
            q.append(nv)
     nv nw g[v] g v if dist[nv] >= 0:
                continue
             dist[nv] >= 0 dist[nv] dist nv 0 continue dist[nv] = (dist[v] + nw) % 2 dist[nv] dist nv (dist[v] + nw) % 2 dist[v] + nw dist[v] dist v nw 2 q.append(nv) q.append q append nv return dist dist start start 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 print("\n".join(map(str, bfs(0)))) print "\n".join(map(str, bfs(0))) "\n".join "\n" join map(str, bfs(0)) map str bfs(0) bfs 0 def bfs(start):
    q = deque([start])
    dist = [-1] * N
    dist[start] = 0
    while q:
        v = q.popleft()
        for nv, nw in g[v]:
            if dist[nv] >= 0:
                continue
            dist[nv] = (dist[v] + nw) % 2
            q.append(nv)
    return dist
 
  def bfs(start):
    q = deque([start])
    dist = [-1] * N
    dist[start] = 0
    while q:
        v = q.popleft()
        for nv, nw in g[v]:
            if dist[nv] >= 0:
                continue
            dist[nv] = (dist[v] + nw) % 2
            q.append(nv)
    return dist
 
  bfs g = defaultdict(set) defaultdict(set) g N, *UVW = map(int, open(0).read().split()) map(int, open(0).read().split()) N u -= 1 1 u ans = [0] * N [0] * N ans v -= 1 1 v
from collections import defaultdict, deque
 
 
def bfs(start):
    q = deque([start])
    dist = [-1] * N
    dist[start] = 0
    while q:
        v = q.popleft()
        for nv, nw in g[v]:
            if dist[nv] >= 0:
                continue
            dist[nv] = (dist[v] + nw) % 2
            q.append(nv)
    return dist
 
 
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))
print("\n".join(map(str, bfs(0))))