# https://atcoder.jp/contests/abc146/tasks/abc146_d



n = int(eval(input()))



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

edges = {}

for i in range(n - 1):

    a, b = list(map(int, input().split()))

    a -= 1

    b -= 1

    graph[a].append(b)

    graph[b].append(a)

    edges[(a, b)] = i

    edges[(b, a)] = i



ans = [0] * (n - 1)

stack = [0]

visited = [-1] * n

visited[0] = 0

while stack:

    node = stack.pop()

    color = 1

    for p in graph[node]:

        if visited[p] < 0:

            if visited[node] == color:

                color += 1

            visited[p] = color

            t = edges[(p, node)]

            ans[t] = color

            stack.append(p)

            color += 1



print((max(ans)))

for a in ans:

    print(a)

from collections import deque

n = int(eval(input()))



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

edges = {}

for i in range(n - 1):

    a, b = list(map(int, input().split()))

    a -= 1

    b -= 1

    graph[a].append(b)

    # graph[b].append(a)

    edges[(a, b)] = i

    # edges[(b, a)] = i



que = deque([0])

ans = [0] * (n - 1)

visited = [-1] * n

visited[0] = 0

while que:

    a = que.popleft()

    c = 1

    for b in graph[a]:

        if visited[b] < 0:

            if visited[a] == c:

                c += 1

            visited[b] = c

            ans[edges[(a, b)]] = c

            c += 1

            que.append(b)



k = max(ans)

print(k)

for i in ans:

    print(i)





# https://atcoder.jp/contests/abc146/tasks/abc146_d
n = int(eval(input()))
graph = [[] for _ in range(n)]
edges = {}
for i in range(n - 1):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
    edges[(a, b)] = i
    edges[(b, a)] = i
ans = [0] * (n - 1)
stack = [0]
visited = [-1] * n
visited[0] = 0
while stack:
    node = stack.pop()
    color = 1
    for p in graph[node]:
        if visited[p] < 0:
            if visited[node] == color:
                color += 1
            visited[p] = color
            t = edges[(p, node)]
            ans[t] = color
            stack.append(p)
            color += 1
print((max(ans)))
for a in ans:
    print(a)

from collections import deque

n = int(eval(input()))
graph = [[] for _ in range(n)]
edges = {}
for i in range(n - 1):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    graph[a].append(b)
    # graph[b].append(a)
    edges[(a, b)] = i
    # edges[(b, a)] = i
que = deque([0])
ans = [0] * (n - 1)
visited = [-1] * n
visited[0] = 0
while que:
    a = que.popleft()
    c = 1
    for b in graph[a]:
        if visited[b] < 0:
            if visited[a] == c:
                c += 1
            visited[b] = c
            ans[edges[(a, b)]] = c
            c += 1
            que.append(b)
k = max(ans)
print(k)
for i in ans:
    print(i)

-# https://atcoder.jp/contests/abc146/tasks/abc146_d +from collections import deque + -    graph[b].append(a) +    # graph[b].append(a) -    edges[(b, a)] = i +    # edges[(b, a)] = i +que = deque([0]) -stack = [0] -while stack: -    node = stack.pop() -    color = 1 -    for p in graph[node]: -        if visited[p] < 0: -            if visited[node] == color: -                color += 1 -            visited[p] = color -            t = edges[(p, node)] -            ans[t] = color -            stack.append(p) -            color += 1 -print((max(ans))) -for a in ans: -    print(a) +while que: +    a = que.popleft() +    c = 1 +    for b in graph[a]: +        if visited[b] < 0: +            if visited[a] == c: +                c += 1 +            visited[b] = c +            ans[edges[(a, b)]] = c +            c += 1 +            que.append(b) +k = max(ans) +print(k) +for i in ans: +    print(i)