import sys

from collections import defaultdict





sys.setrecursionlimit(1_000_000)





def dfs(v):

    for nv, nw in g[v]:

        if visited[nv]:

            continue

        if nw % 2:

            ans[nv] = ans[v] ^ 1

        else:

            ans[nv] = ans[v]

        visited[nv] = True

        dfs(nv)





N, *UVW = list(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 = [False] * N

visited[0] = True

dfs(0)

print(("\n".join(map(str, ans))))



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 = list(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)))))

import sys
from collections import defaultdict

sys.setrecursionlimit(1_000_000)


def dfs(v):
    for nv, nw in g[v]:
        if visited[nv]:
            continue
        if nw % 2:
            ans[nv] = ans[v] ^ 1
        else:
            ans[nv] = ans[v]
        visited[nv] = True
        dfs(nv)


N, *UVW = list(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 = [False] * N
visited[0] = True
dfs(0)
print(("\n".join(map(str, ans))))

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 = list(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)))))

-import sys -from collections import defaultdict - -sys.setrecursionlimit(1_000_000) +from collections import defaultdict, deque -def dfs(v): -    for nv, nw in g[v]: -        if visited[nv]: -            continue -        if nw % 2: -            ans[nv] = ans[v] ^ 1 -        else: -            ans[nv] = ans[v] -        visited[nv] = True -        dfs(nv) +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 -visited = [False] * N -visited[0] = True -dfs(0) -print(("\n".join(map(str, ans)))) +print(("\n".join(map(str, bfs(0)))))