from collections import deque

N = int(input())

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



graph = [[] for _ in range(N)]

tree = [[] for _ in range(N)]

for n, (i, j) in enumerate(X):

    graph[i - 1].append(j - 1)

    graph[j - 1].append(i - 1)

    

    tree[i - 1].append((n, j - 1))

    

K = max(len(x) for x in graph)

q = deque()

q.append((0, 0))

ans = [0] * (N - 1)



while len(q) > 0:

    # u: node number, c: color

    u, c = q.popleft()

    

    cnt = 1

    for i, (n, v) in enumerate(tree[u]):

        if cnt == c:

            cnt += 1



        ans[n] = cnt

        q.append((v, cnt))

        cnt += 1

        

print(K)

print(*ans, sep="\n")

from collections import deque

N = int(input())

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



tree = [[] for _ in range(N)]

for n, (i, j) in enumerate(X):

    tree[i - 1].append((n, j - 1))



q = deque()

q.append((0, 0))

ans = [0] * (N - 1)



while len(q) > 0:

    # u: node number, c: color

    u, c = q.popleft()

    

    cnt = 1

    for i, (n, v) in enumerate(tree[u]):

        if cnt == c:

            cnt += 1



        ans[n] = cnt

        q.append((v, cnt))

        cnt += 1

        

print(max(ans))

print(*ans, sep="\n")

from collections import deque

N = int(input())
X = [list(map(int, input().split())) for _ in range(N - 1)]
graph = [[] for _ in range(N)]
tree = [[] for _ in range(N)]
for n, (i, j) in enumerate(X):
    graph[i - 1].append(j - 1)
    graph[j - 1].append(i - 1)
    tree[i - 1].append((n, j - 1))
K = max(len(x) for x in graph)
q = deque()
q.append((0, 0))
ans = [0] * (N - 1)
while len(q) > 0:
    # u: node number, c: color
    u, c = q.popleft()
    cnt = 1
    for i, (n, v) in enumerate(tree[u]):
        if cnt == c:
            cnt += 1
        ans[n] = cnt
        q.append((v, cnt))
        cnt += 1
print(K)
print(*ans, sep="\n")

from collections import deque

N = int(input())
X = [list(map(int, input().split())) for _ in range(N - 1)]
tree = [[] for _ in range(N)]
for n, (i, j) in enumerate(X):
    tree[i - 1].append((n, j - 1))
q = deque()
q.append((0, 0))
ans = [0] * (N - 1)
while len(q) > 0:
    # u: node number, c: color
    u, c = q.popleft()
    cnt = 1
    for i, (n, v) in enumerate(tree[u]):
        if cnt == c:
            cnt += 1
        ans[n] = cnt
        q.append((v, cnt))
        cnt += 1
print(max(ans))
print(*ans, sep="\n")

-graph = [[] for _ in range(N)] -    graph[i - 1].append(j - 1) -    graph[j - 1].append(i - 1) -K = max(len(x) for x in graph) -print(K) +print(max(ans))