from sys import stdin
input = stdin.buffer.readline

def main():
    n = int(input())

    edges = [[] for _ in range(n)]
    for _ in range(n-1):
        u, v, w = map(int, input().split())
        edges[u-1].append((v-1, w%2))
        edges[v-1].append((u-1, w%2))

    ans = [-1] * n
    ans[0] = 0
    todo = [0]
    while len(todo) > 0:
        parent = todo.pop(-1)
        color = ans[parent]

        for child, w in edges[parent]:
            if ans[child] == -1:
                if w == 0:
                    ans[child] = color
                else:
                    ans[child] = 1 - color
                todo.append(child)

    for i in ans:
        print(i)

main() from sys import stdin input = stdin.buffer.readline input stdin.buffer.readline stdin.buffer stdin buffer readline def main():
    n = int(input())

    edges = [[] for _ in range(n)]
    for _ in range(n-1):
        u, v, w = map(int, input().split())
        edges[u-1].append((v-1, w%2))
        edges[v-1].append((u-1, w%2))

    ans = [-1] * n
    ans[0] = 0
    todo = [0]
    while len(todo) > 0:
        parent = todo.pop(-1)
        color = ans[parent]

        for child, w in edges[parent]:
            if ans[child] == -1:
                if w == 0:
                    ans[child] = color
                else:
                    ans[child] = 1 - color
                todo.append(child)

    for i in ans:
        print(i) main n = int(input()) n int(input()) int input() input [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] edges = [[] for _ in range(n)] edges [[] for _ in range(n)] for _ in range(n-1):
        u, v, w = map(int, input().split())
        edges[u-1].append((v-1, w%2))
        edges[v-1].append((u-1, w%2))

     _ range(n-1) range n-1 n 1 u, v, w = map(int, input().split()) u map(int, input().split()) map int input().split() ().split () input split v w edges[u-1].append((v-1, w%2)) [u-1].append [u-1] edges u-1 u 1 append (v-1, w%2) v-1 v 1 w%2 w 2 edges[v-1].append((u-1, w%2)) [v-1].append [v-1] edges v-1 v 1 append (u-1, w%2) u-1 u 1 w%2 w 2 ans = [-1] * n ans [-1] * n [-1] -1 n ans[0] = 0 ans[0] ans 0 0 todo = [0] todo [0] 0 while len(todo) > 0:
        parent = todo.pop(-1)
        color = ans[parent]

        for child, w in edges[parent]:
            if ans[child] == -1:
                if w == 0:
                    ans[child] = color
                else:
                    ans[child] = 1 - color
                todo.append(child)

     len(todo) > 0 len(todo) len todo 0 parent = todo.pop(-1) parent todo.pop(-1) todo.pop todo pop -1 color = ans[parent] color ans[parent] ans parent for child, w in edges[parent]:
            if ans[child] == -1:
                if w == 0:
                    ans[child] = color
                else:
                    ans[child] = 1 - color
                todo.append(child)

     child w edges[parent] edges parent if ans[child] == -1:
                if w == 0:
                    ans[child] = color
                else:
                    ans[child] = 1 - color
                todo.append(child)

     ans[child] == -1 ans[child] ans child -1 if w == 0:
                    ans[child] = color
                else:
                    ans[child] = 1 - color
                 w == 0 w 0 ans[child] = color ans[child] ans child color ans[child] = 1 - color ans[child] ans child 1 - color 1 color todo.append(child) todo.append todo append child for i in ans:
        print(i) i ans print(i) print i main() main input = stdin.buffer.readline stdin.buffer.readline input def main():
    n = int(input())

    edges = [[] for _ in range(n)]
    for _ in range(n-1):
        u, v, w = map(int, input().split())
        edges[u-1].append((v-1, w%2))
        edges[v-1].append((u-1, w%2))

    ans = [-1] * n
    ans[0] = 0
    todo = [0]
    while len(todo) > 0:
        parent = todo.pop(-1)
        color = ans[parent]

        for child, w in edges[parent]:
            if ans[child] == -1:
                if w == 0:
                    ans[child] = color
                else:
                    ans[child] = 1 - color
                todo.append(child)

    for i in ans:
        print(i) def main():
    n = int(input())

    edges = [[] for _ in range(n)]
    for _ in range(n-1):
        u, v, w = map(int, input().split())
        edges[u-1].append((v-1, w%2))
        edges[v-1].append((u-1, w%2))

    ans = [-1] * n
    ans[0] = 0
    todo = [0]
    while len(todo) > 0:
        parent = todo.pop(-1)
        color = ans[parent]

        for child, w in edges[parent]:
            if ans[child] == -1:
                if w == 0:
                    ans[child] = color
                else:
                    ans[child] = 1 - color
                todo.append(child)

    for i in ans:
        print(i) main
from sys import stdin
input = stdin.buffer.readline

def main():
    n = int(input())

    edges = [[] for _ in range(n)]
    for _ in range(n-1):
        u, v, w = map(int, input().split())
        edges[u-1].append((v-1, w%2))
        edges[v-1].append((u-1, w%2))

    ans = [-1] * n
    ans[0] = 0
    todo = [0]
    while len(todo) > 0:
        parent = todo.pop(-1)
        color = ans[parent]

        for child, w in edges[parent]:
            if ans[child] == -1:
                if w == 0:
                    ans[child] = color
                else:
                    ans[child] = 1 - color
                todo.append(child)

    for i in ans:
        print(i)

main()