#!/usr/bin/env python3
from collections import deque
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, u: "List[int]", v: "List[int]", w: "List[int]"):
    G = [[] for _ in range(N)]
    for ui, vi, wi in zip(u, v, w):
        ui -= 1
        vi -= 1
        G[ui].append((vi, wi))
        G[vi].append((ui, wi))
    color = [-1] * N
    color[0] = 0
    q = deque([0])
    while q:
        s = q.popleft()
        for t, wi in G[s]:
            if color[t] >= 0:
                continue
            color[t] = (color[s] + wi) % 2
            q.append(t)
    for colori in color:
        print(colori)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    u = [int()] * (N - 1)  # type: "List[int]"
    v = [int()] * (N - 1)  # type: "List[int]"
    w = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        u[i] = int(next(tokens))
        v[i] = int(next(tokens))
        w[i] = int(next(tokens))
    solve(N, u, v, w)


if __name__ == '__main__':
    main() from collections import deque import sys sys try:
    from typing import List
except ImportError:
    pass except ImportError:
    pass from typing import List def solve(N: int, u: "List[int]", v: "List[int]", w: "List[int]"):
    G = [[] for _ in range(N)]
    for ui, vi, wi in zip(u, v, w):
        ui -= 1
        vi -= 1
        G[ui].append((vi, wi))
        G[vi].append((ui, wi))
    color = [-1] * N
    color[0] = 0
    q = deque([0])
    while q:
        s = q.popleft()
        for t, wi in G[s]:
            if color[t] >= 0:
                continue
            color[t] = (color[s] + wi) % 2
            q.append(t)
    for colori in color:
        print(colori) solve [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] G = [[] for _ in range(N)] G [[] for _ in range(N)] for ui, vi, wi in zip(u, v, w):
        ui -= 1
        vi -= 1
        G[ui].append((vi, wi))
        G[vi].append((ui, wi))
     ui vi wi zip(u, v, w) zip u v w ui -= 1 ui 1 vi -= 1 vi 1 G[ui].append((vi, wi)) [ui].append [ui] G ui append (vi, wi) vi wi G[vi].append((ui, wi)) [vi].append [vi] G vi append (ui, wi) ui wi color = [-1] * N color [-1] * N [-1] -1 N color[0] = 0 color[0] color 0 0 q = deque([0]) q deque([0]) deque [0] 0 while q:
        s = q.popleft()
        for t, wi in G[s]:
            if color[t] >= 0:
                continue
            color[t] = (color[s] + wi) % 2
            q.append(t)
     q s = q.popleft() s q.popleft() q.popleft q popleft for t, wi in G[s]:
            if color[t] >= 0:
                continue
            color[t] = (color[s] + wi) % 2
            q.append(t)
     t wi G[s] G s if color[t] >= 0:
                continue
             color[t] >= 0 color[t] color t 0 continue color[t] = (color[s] + wi) % 2 color[t] color t (color[s] + wi) % 2 color[s] + wi color[s] color s wi 2 q.append(t) q.append q append t for colori in color:
        print(colori) colori color print(colori) print colori N: int N u: "List[int]" u v: "List[int]" v w: "List[int]" w def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    u = [int()] * (N - 1)  # type: "List[int]"
    v = [int()] * (N - 1)  # type: "List[int]"
    w = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        u[i] = int(next(tokens))
        v[i] = int(next(tokens))
        w[i] = int(next(tokens))
    solve(N, u, v, w) main def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
     iterate_tokens for line in sys.stdin:
            for word in line.split():
                yield word
     line sys.stdin sys stdin for word in line.split():
                yield word
     word line.split() line.split line split yield word word tokens = iterate_tokens() tokens iterate_tokens() iterate_tokens N = int(next(tokens)) N int(next(tokens)) int next(tokens) next tokens u = [int()] * (N - 1) u [int()] * (N - 1) [int()] int() int N - 1 N 1 v = [int()] * (N - 1) v [int()] * (N - 1) [int()] int() int N - 1 N 1 w = [int()] * (N - 1) w [int()] * (N - 1) [int()] int() int N - 1 N 1 for i in range(N - 1):
        u[i] = int(next(tokens))
        v[i] = int(next(tokens))
        w[i] = int(next(tokens))
     i range(N - 1) range N - 1 N 1 u[i] = int(next(tokens)) u[i] u i int(next(tokens)) int next(tokens) next tokens v[i] = int(next(tokens)) v[i] v i int(next(tokens)) int next(tokens) next tokens w[i] = int(next(tokens)) w[i] w i int(next(tokens)) int next(tokens) next tokens solve(N, u, v, w) solve N u v w if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    u = [int()] * (N - 1)  # type: "List[int]"
    v = [int()] * (N - 1)  # type: "List[int]"
    w = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        u[i] = int(next(tokens))
        v[i] = int(next(tokens))
        w[i] = int(next(tokens))
    solve(N, u, v, w) def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    u = [int()] * (N - 1)  # type: "List[int]"
    v = [int()] * (N - 1)  # type: "List[int]"
    w = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        u[i] = int(next(tokens))
        v[i] = int(next(tokens))
        w[i] = int(next(tokens))
    solve(N, u, v, w) main def solve(N: int, u: "List[int]", v: "List[int]", w: "List[int]"):
    G = [[] for _ in range(N)]
    for ui, vi, wi in zip(u, v, w):
        ui -= 1
        vi -= 1
        G[ui].append((vi, wi))
        G[vi].append((ui, wi))
    color = [-1] * N
    color[0] = 0
    q = deque([0])
    while q:
        s = q.popleft()
        for t, wi in G[s]:
            if color[t] >= 0:
                continue
            color[t] = (color[s] + wi) % 2
            q.append(t)
    for colori in color:
        print(colori) def solve(N: int, u: "List[int]", v: "List[int]", w: "List[int]"):
    G = [[] for _ in range(N)]
    for ui, vi, wi in zip(u, v, w):
        ui -= 1
        vi -= 1
        G[ui].append((vi, wi))
        G[vi].append((ui, wi))
    color = [-1] * N
    color[0] = 0
    q = deque([0])
    while q:
        s = q.popleft()
        for t, wi in G[s]:
            if color[t] >= 0:
                continue
            color[t] = (color[s] + wi) % 2
            q.append(t)
    for colori in color:
        print(colori) solve
#!/usr/bin/env python3
from collections import deque
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, u: "List[int]", v: "List[int]", w: "List[int]"):
    G = [[] for _ in range(N)]
    for ui, vi, wi in zip(u, v, w):
        ui -= 1
        vi -= 1
        G[ui].append((vi, wi))
        G[vi].append((ui, wi))
    color = [-1] * N
    color[0] = 0
    q = deque([0])
    while q:
        s = q.popleft()
        for t, wi in G[s]:
            if color[t] >= 0:
                continue
            color[t] = (color[s] + wi) % 2
            q.append(t)
    for colori in color:
        print(colori)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    u = [int()] * (N - 1)  # type: "List[int]"
    v = [int()] * (N - 1)  # type: "List[int]"
    w = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        u[i] = int(next(tokens))
        v[i] = int(next(tokens))
        w[i] = int(next(tokens))
    solve(N, u, v, w)


if __name__ == '__main__':
    main()
