"""

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), *(C[b] for b in 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)))

	print(("\n".join(str(C[b]) for b in 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), *(C[b] for b in 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)))
    print(("\n".join(str(C[b]) for b in B)))


main()

-    print((max(C), *(C[b] for b in B))) +    print((max(C))) +    print(("\n".join(str(C[b]) for b in B)))