def main():
    from collections import deque, defaultdict
    n, *uvw = map(int, open(0).read().split())
    l = defaultdict(dict)
    g = [[] for _ in range(n + 1)]

    for u, v, w in zip(uvw[::3], uvw[1::3], uvw[2::3]):
        g[u].append(v)
        g[v].append(u)
        l[u].update({v: w % 2})

    l[0].update({1: 0})

    vis = [False] * (n + 1)
    col = [0] * (n + 1)

    q = deque()
    q.append([0, 1, 0])

    while q:
        i, j, k = q.popleft()
        if vis[j]:
            continue
        vis[j] = True
        c = k if l[min(i, j)][max(i, j)] == 0 else 1 - k
        col[j] = c

        for x in g[j]:
            q.appendleft([j, x, c])

    print(*col[1:], sep='\n')


if __name__ == '__main__':
    main() def main():
    from collections import deque, defaultdict
    n, *uvw = map(int, open(0).read().split())
    l = defaultdict(dict)
    g = [[] for _ in range(n + 1)]

    for u, v, w in zip(uvw[::3], uvw[1::3], uvw[2::3]):
        g[u].append(v)
        g[v].append(u)
        l[u].update({v: w % 2})

    l[0].update({1: 0})

    vis = [False] * (n + 1)
    col = [0] * (n + 1)

    q = deque()
    q.append([0, 1, 0])

    while q:
        i, j, k = q.popleft()
        if vis[j]:
            continue
        vis[j] = True
        c = k if l[min(i, j)][max(i, j)] == 0 else 1 - k
        col[j] = c

        for x in g[j]:
            q.appendleft([j, x, c])

    print(*col[1:], sep='\n') main from collections import deque, defaultdict 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 l = defaultdict(dict) l defaultdict(dict) defaultdict dict [] for _ in range(n + 1) for _ in range(n + 1) _ range(n + 1) range n + 1 n 1 for _ in range(n + 1) [] g = [[] for _ in range(n + 1)] g [[] for _ in range(n + 1)] for u, v, w in zip(uvw[::3], uvw[1::3], uvw[2::3]):
        g[u].append(v)
        g[v].append(u)
        l[u].update({v: w % 2})

     u v w zip(uvw[::3], uvw[1::3], uvw[2::3]) zip uvw[::3] uvw ::3 3 uvw[1::3] uvw 1::3 1 3 uvw[2::3] uvw 2::3 2 3 g[u].append(v) [u].append [u] g u append v g[v].append(u) [v].append [v] g v append u l[u].update({v: w % 2}) [u].update [u] l u update {v: w % 2} v v w % 2 w 2 l[0].update({1: 0}) [0].update [0] l 0 update {1: 0} 1 1 0 vis = [False] * (n + 1) vis [False] * (n + 1) [False] False n + 1 n 1 col = [0] * (n + 1) col [0] * (n + 1) [0] 0 n + 1 n 1 q = deque() q deque() deque q.append([0, 1, 0]) q.append q append [0, 1, 0] 0 1 0 while q:
        i, j, k = q.popleft()
        if vis[j]:
            continue
        vis[j] = True
        c = k if l[min(i, j)][max(i, j)] == 0 else 1 - k
        col[j] = c

        for x in g[j]:
            q.appendleft([j, x, c])

     q i, j, k = q.popleft() i q.popleft() q.popleft q popleft j k if vis[j]:
            continue
         vis[j] vis j continue vis[j] = True vis[j] vis j True c = k if l[min(i, j)][max(i, j)] == 0 else 1 - k c k if l[min(i, j)][max(i, j)] == 0 else 1 - k l[min(i, j)][max(i, j)] == 0 l[min(i, j)][max(i, j)] [min(i, j)] l min(i, j) min i j max(i, j) max i j 0 k 1 - k 1 k col[j] = c col[j] col j c for x in g[j]:
            q.appendleft([j, x, c])

     x g[j] g j q.appendleft([j, x, c]) q.appendleft q appendleft [j, x, c] j x c print(*col[1:], sep='\n') print *col[1:] col[1:] col 1: 1 sep='\n' sep '\n' if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    from collections import deque, defaultdict
    n, *uvw = map(int, open(0).read().split())
    l = defaultdict(dict)
    g = [[] for _ in range(n + 1)]

    for u, v, w in zip(uvw[::3], uvw[1::3], uvw[2::3]):
        g[u].append(v)
        g[v].append(u)
        l[u].update({v: w % 2})

    l[0].update({1: 0})

    vis = [False] * (n + 1)
    col = [0] * (n + 1)

    q = deque()
    q.append([0, 1, 0])

    while q:
        i, j, k = q.popleft()
        if vis[j]:
            continue
        vis[j] = True
        c = k if l[min(i, j)][max(i, j)] == 0 else 1 - k
        col[j] = c

        for x in g[j]:
            q.appendleft([j, x, c])

    print(*col[1:], sep='\n') def main():
    from collections import deque, defaultdict
    n, *uvw = map(int, open(0).read().split())
    l = defaultdict(dict)
    g = [[] for _ in range(n + 1)]

    for u, v, w in zip(uvw[::3], uvw[1::3], uvw[2::3]):
        g[u].append(v)
        g[v].append(u)
        l[u].update({v: w % 2})

    l[0].update({1: 0})

    vis = [False] * (n + 1)
    col = [0] * (n + 1)

    q = deque()
    q.append([0, 1, 0])

    while q:
        i, j, k = q.popleft()
        if vis[j]:
            continue
        vis[j] = True
        c = k if l[min(i, j)][max(i, j)] == 0 else 1 - k
        col[j] = c

        for x in g[j]:
            q.appendleft([j, x, c])

    print(*col[1:], sep='\n') main
def main():
    from collections import deque, defaultdict
    n, *uvw = map(int, open(0).read().split())
    l = defaultdict(dict)
    g = [[] for _ in range(n + 1)]

    for u, v, w in zip(uvw[::3], uvw[1::3], uvw[2::3]):
        g[u].append(v)
        g[v].append(u)
        l[u].update({v: w % 2})

    l[0].update({1: 0})

    vis = [False] * (n + 1)
    col = [0] * (n + 1)

    q = deque()
    q.append([0, 1, 0])

    while q:
        i, j, k = q.popleft()
        if vis[j]:
            continue
        vis[j] = True
        c = k if l[min(i, j)][max(i, j)] == 0 else 1 - k
        col[j] = c

        for x in g[j]:
            q.appendleft([j, x, c])

    print(*col[1:], sep='\n')


if __name__ == '__main__':
    main()
