"""

challenge case



in:

3

1 3

2 3



out:

1

1

1

"""



from collections import deque



def main():

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

	B = AB[1::2]



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

	for a, b in zip(*[iter(AB)] * 2):

		E[a] += b,



	Q = deque([1])

	C = [0] * (N + 1)

	while Q:

		v = Q.popleft()

		c = 0

		for u in E[v]:

			c += 1 + (c + 1 == C[v])

			C[u] = c

			Q += u,



	print((max(C)))

	for b in B:

		print((C[b]))



main()
"""

challenge case



in:

3

1 3

2 3



out:

1

1

1

"""



from collections import deque



def main():

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

	B = AB[1::2]



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

	for a, b in zip(*[iter(AB)] * 2):

		E[a].append(b)



	Q = deque([1])

	C = [0] * (N + 1)

	while Q:

		v = Q.popleft()

		c = 0

		for u in E[v]:

			c += 1 + (c + 1 == C[v])

			C[u] = c

			Q.append(u)



	print((max(C)))

	for b in B:

		print((C[b]))



main()
"""
challenge case
in:
3
1 3
2 3
out:
1
1
1
"""
from collections import deque


def main():
    N, *AB = list(map(int, open(0).read().split()))
    B = AB[1::2]
    E = [[] for _ in range(N + 1)]
    for a, b in zip(*[iter(AB)] * 2):
        E[a] += (b,)
    Q = deque([1])
    C = [0] * (N + 1)
    while Q:
        v = Q.popleft()
        c = 0
        for u in E[v]:
            c += 1 + (c + 1 == C[v])
            C[u] = c
            Q += (u,)
    print((max(C)))
    for b in B:
        print((C[b]))


main()

"""
challenge case
in:
3
1 3
2 3
out:
1
1
1
"""
from collections import deque


def main():
    N, *AB = list(map(int, open(0).read().split()))
    B = AB[1::2]
    E = [[] for _ in range(N + 1)]
    for a, b in zip(*[iter(AB)] * 2):
        E[a].append(b)
    Q = deque([1])
    C = [0] * (N + 1)
    while Q:
        v = Q.popleft()
        c = 0
        for u in E[v]:
            c += 1 + (c + 1 == C[v])
            C[u] = c
            Q.append(u)
    print((max(C)))
    for b in B:
        print((C[b]))


main()

-        E[a] += (b,) +        E[a].append(b) -            Q += (u,) +            Q.append(u)