N, *m=map(int, open(0).read().split())

im = iter(m)
UVW = list(zip(im, im, im))

# set default color to -1

colors = {i:-1 for i in range(1,N+1)}
u,v,w = UVW[0]
colors[u] = 0

def opposite(u, v):
    if v == -1:
        return u
    if v == 0:
        return 1
    if v == 1:
        return 0

def same(u, v):
    if v == -1:
        return u
    else:
        return v

while -1 in colors.values():
    next_UVW = []
    for u, v, w in UVW:
        if colors[u] == -1 and colors[v] == -1:
            next_UVW.append((u, v, w))
            continue

        if w % 2 == 0:
            colors[u] = same(colors[u], colors[v])
            colors[v] = same(colors[v], colors[u])

        if w % 2 == 1:
            colors[u] = opposite(colors[u], colors[v])
            colors[v] = opposite(colors[v], colors[u])

        if colors[u] == -1 or colors[v] == -1:
            next_UVW.append((u,v,w))

    UVW = next_UVW



for i in range(1, N+1):
    print(colors[i]) N, *m=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 *m m im = iter(m) im iter(m) iter m UVW = list(zip(im, im, im)) UVW list(zip(im, im, im)) list zip(im, im, im) zip im im im i:-1 for i in range(1,N+1) for i in range(1,N+1) i range(1,N+1) range 1 N+1 N 1 for i in range(1,N+1) i -1 colors = {i:-1 for i in range(1,N+1)} colors {i:-1 for i in range(1,N+1)} u,v,w = UVW[0] u UVW[0] UVW 0 v w colors[u] = 0 colors[u] colors u 0 def opposite(u, v):
    if v == -1:
        return u
    if v == 0:
        return 1
    if v == 1:
        return 0 opposite if v == -1:
        return u
     v == -1 v -1 return u u if v == 0:
        return 1
     v == 0 v 0 return 1 1 if v == 1:
        return 0 v == 1 v 1 return 0 0 u u v v def same(u, v):
    if v == -1:
        return u
    else:
        return v same if v == -1:
        return u
    else:
        return v v == -1 v -1 return u u return v v u u v v while -1 in colors.values():
    next_UVW = []
    for u, v, w in UVW:
        if colors[u] == -1 and colors[v] == -1:
            next_UVW.append((u, v, w))
            continue

        if w % 2 == 0:
            colors[u] = same(colors[u], colors[v])
            colors[v] = same(colors[v], colors[u])

        if w % 2 == 1:
            colors[u] = opposite(colors[u], colors[v])
            colors[v] = opposite(colors[v], colors[u])

        if colors[u] == -1 or colors[v] == -1:
            next_UVW.append((u,v,w))

    UVW = next_UVW -1 in colors.values() -1 colors.values() colors.values colors values next_UVW = [] next_UVW [] for u, v, w in UVW:
        if colors[u] == -1 and colors[v] == -1:
            next_UVW.append((u, v, w))
            continue

        if w % 2 == 0:
            colors[u] = same(colors[u], colors[v])
            colors[v] = same(colors[v], colors[u])

        if w % 2 == 1:
            colors[u] = opposite(colors[u], colors[v])
            colors[v] = opposite(colors[v], colors[u])

        if colors[u] == -1 or colors[v] == -1:
            next_UVW.append((u,v,w))

     u v w UVW if colors[u] == -1 and colors[v] == -1:
            next_UVW.append((u, v, w))
            continue

         colors[u] == -1 and colors[v] == -1 colors[u] == -1 colors[u] colors u -1 colors[v] == -1 colors[v] colors v -1 next_UVW.append((u, v, w)) next_UVW.append next_UVW append (u, v, w) u v w continue if w % 2 == 0:
            colors[u] = same(colors[u], colors[v])
            colors[v] = same(colors[v], colors[u])

         w % 2 == 0 w % 2 w 2 0 colors[u] = same(colors[u], colors[v]) colors[u] colors u same(colors[u], colors[v]) same colors[u] colors u colors[v] colors v colors[v] = same(colors[v], colors[u]) colors[v] colors v same(colors[v], colors[u]) same colors[v] colors v colors[u] colors u if w % 2 == 1:
            colors[u] = opposite(colors[u], colors[v])
            colors[v] = opposite(colors[v], colors[u])

         w % 2 == 1 w % 2 w 2 1 colors[u] = opposite(colors[u], colors[v]) colors[u] colors u opposite(colors[u], colors[v]) opposite colors[u] colors u colors[v] colors v colors[v] = opposite(colors[v], colors[u]) colors[v] colors v opposite(colors[v], colors[u]) opposite colors[v] colors v colors[u] colors u if colors[u] == -1 or colors[v] == -1:
            next_UVW.append((u,v,w))

     colors[u] == -1 or colors[v] == -1 colors[u] == -1 colors[u] colors u -1 colors[v] == -1 colors[v] colors v -1 next_UVW.append((u,v,w)) next_UVW.append next_UVW append (u,v,w) u v w UVW = next_UVW UVW next_UVW for i in range(1, N+1):
    print(colors[i]) i range(1, N+1) range 1 N+1 N 1 print(colors[i]) print colors[i] colors i im = iter(m) iter(m) im w = UVW[0] UVW[0] w def opposite(u, v):
    if v == -1:
        return u
    if v == 0:
        return 1
    if v == 1:
        return 0 def opposite(u, v):
    if v == -1:
        return u
    if v == 0:
        return 1
    if v == 1:
        return 0 opposite N, *m=map(int, open(0).read().split()) map(int, open(0).read().split()) N colors = {i:-1 for i in range(1,N+1)} {i:-1 for i in range(1,N+1)} colors u,v,w = UVW[0] UVW[0] u v,w = UVW[0] UVW[0] v def same(u, v):
    if v == -1:
        return u
    else:
        return v def same(u, v):
    if v == -1:
        return u
    else:
        return v same next_UVW = [] [] next_UVW UVW = list(zip(im, im, im)) list(zip(im, im, im)) UVW UVW = next_UVW next_UVW UVW
N, *m=map(int, open(0).read().split())

im = iter(m)
UVW = list(zip(im, im, im))

# set default color to -1

colors = {i:-1 for i in range(1,N+1)}
u,v,w = UVW[0]
colors[u] = 0

def opposite(u, v):
    if v == -1:
        return u
    if v == 0:
        return 1
    if v == 1:
        return 0

def same(u, v):
    if v == -1:
        return u
    else:
        return v

while -1 in colors.values():
    next_UVW = []
    for u, v, w in UVW:
        if colors[u] == -1 and colors[v] == -1:
            next_UVW.append((u, v, w))
            continue

        if w % 2 == 0:
            colors[u] = same(colors[u], colors[v])
            colors[v] = same(colors[v], colors[u])

        if w % 2 == 1:
            colors[u] = opposite(colors[u], colors[v])
            colors[v] = opposite(colors[v], colors[u])

        if colors[u] == -1 or colors[v] == -1:
            next_UVW.append((u,v,w))

    UVW = next_UVW



for i in range(1, N+1):
    print(colors[i])