import copy

import sys



sys.setrecursionlimit(10 ** 7)



N = int(eval(input()))

uvw = [list(map(int, input().split(' '))) for _ in range(N - 1)]



# 適当に最初の色を決める

# その点を親として、

# 親からの距離が偶数だったら親と同じ色

# 親からの距離が奇数だったら親と違う色



children = [[] for _ in range(N + 1)]



for e in uvw:

    children[e[0]].append([e[1], e[2]])

    children[e[1]].append([e[0], e[2]])



pool = [1]

result = [0 for i in range(N + 1)]  # 頂点1は白くする



marked = set()

marked.add(1)



while pool:

    top = pool.pop()

    for child in children[top]:

        child_edge = child[0]

        length = child[1]



        if child_edge not in marked:

            pool.append(child_edge)

            marked.add(child_edge)

        if length % 2 == 0:

            result[child_edge] = 0 if result[top] == 0 else 1

        else:

            result[child_edge] = 1 if result[top] == 0 else 0



for i in result[1:]:

    print(i)

#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10 ** 7)

 

def solve(N: int, u: "List[int]", v: "List[int]", w: "List[int]"):

    res = [0 for i in range(N)]

    G = [[] for i in range(N)]

    for i, j, k in zip(u, v, w):

        # print(i, j, k)

        i -= 1

        j -= 1

        # print(i, j, k)

        G[i].append((j, k))

        G[j].append((i, k))

 

    # v を c に塗る。 p は v の親。

    def dfs(v, p, c):

        res[v] = c

        for e in G[v]:

            if e[0] == p:

                continue

            if e[1] & 1:

                dfs(e[0], v, 1 - c)

            else:

                dfs(e[0], v, c)

 

    dfs(0, -1, 1)

 

    for x in res:

        print(x)

 

    return

 

 

# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools

# (tips: You use the default template now. You can remove this line by using your custom template)

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()
import copy
import sys

sys.setrecursionlimit(10**7)
N = int(eval(input()))
uvw = [list(map(int, input().split(" "))) for _ in range(N - 1)]
# 適当に最初の色を決める
# その点を親として、
# 親からの距離が偶数だったら親と同じ色
# 親からの距離が奇数だったら親と違う色
children = [[] for _ in range(N + 1)]
for e in uvw:
    children[e[0]].append([e[1], e[2]])
    children[e[1]].append([e[0], e[2]])
pool = [1]
result = [0 for i in range(N + 1)]  # 頂点1は白くする
marked = set()
marked.add(1)
while pool:
    top = pool.pop()
    for child in children[top]:
        child_edge = child[0]
        length = child[1]
        if child_edge not in marked:
            pool.append(child_edge)
            marked.add(child_edge)
        if length % 2 == 0:
            result[child_edge] = 0 if result[top] == 0 else 1
        else:
            result[child_edge] = 1 if result[top] == 0 else 0
for i in result[1:]:
    print(i)

#!/usr/bin/env python3
import sys

sys.setrecursionlimit(10**7)


def solve(N: int, u: "List[int]", v: "List[int]", w: "List[int]"):
    res = [0 for i in range(N)]
    G = [[] for i in range(N)]
    for i, j, k in zip(u, v, w):
        # print(i, j, k)
        i -= 1
        j -= 1
        # print(i, j, k)
        G[i].append((j, k))
        G[j].append((i, k))
    # v を c に塗る。 p は v の親。
    def dfs(v, p, c):
        res[v] = c
        for e in G[v]:
            if e[0] == p:
                continue
            if e[1] & 1:
                dfs(e[0], v, 1 - c)
            else:
                dfs(e[0], v, c)

    dfs(0, -1, 1)
    for x in res:
        print(x)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools
# (tips: You use the default template now. You can remove this line by using your custom template)
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()

-import copy +#!/usr/bin/env python3 -N = int(eval(input())) -uvw = [list(map(int, input().split(" "))) for _ in range(N - 1)] -# 適当に最初の色を決める -# その点を親として、 -# 親からの距離が偶数だったら親と同じ色 -# 親からの距離が奇数だったら親と違う色 -children = [[] for _ in range(N + 1)] -for e in uvw: -    children[e[0]].append([e[1], e[2]]) -    children[e[1]].append([e[0], e[2]]) -pool = [1] -result = [0 for i in range(N + 1)]  # 頂点1は白くする -marked = set() -marked.add(1) -while pool: -    top = pool.pop() -    for child in children[top]: -        child_edge = child[0] -        length = child[1] -        if child_edge not in marked: -            pool.append(child_edge) -            marked.add(child_edge) -        if length % 2 == 0: -            result[child_edge] = 0 if result[top] == 0 else 1 -        else: -            result[child_edge] = 1 if result[top] == 0 else 0 -for i in result[1:]: -    print(i) + + +def solve(N: int, u: "List[int]", v: "List[int]", w: "List[int]"): +    res = [0 for i in range(N)] +    G = [[] for i in range(N)] +    for i, j, k in zip(u, v, w): +        # print(i, j, k) +        i -= 1 +        j -= 1 +        # print(i, j, k) +        G[i].append((j, k)) +        G[j].append((i, k)) +    # v を c に塗る。 p は v の親。 +    def dfs(v, p, c): +        res[v] = c +        for e in G[v]: +            if e[0] == p: +                continue +            if e[1] & 1: +                dfs(e[0], v, 1 - c) +            else: +                dfs(e[0], v, c) + +    dfs(0, -1, 1) +    for x in res: +        print(x) +    return + + +# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools +# (tips: You use the default template now. You can remove this line by using your custom template) +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()