import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



N = int(readline())

AB = [list(map(int,readline().split())) for i in range(N-1)]



graph = [[] for _ in range(N+1)] #隣接リスト

for a,b in AB:

    graph[a].append(b)

    graph[b].append(a)



#親のノードに子を入れてくdfs

stack = [1]

parent = [0]*(N+1)

order = []

while stack:

    x = stack.pop()

    order.append(x)

    for i in graph[x]:

        if i == parent[x]:

            continue

        parent[i] = x

        stack.append(i)



#各子の色を決めていく。

color = [-1]*(N+1)

for x in order:

    ng = color[x]

    c = 1

    for y in graph[x]:

        if parent[x] == y:

            continue

        if c == ng:

            c += 1

        color[y] = c

        c += 1



ans = []

for a,b in AB:

    if parent[a] == b: #子の頂点の色を入れる

        ans.append(color[a])

    else:

        ans.append(color[b])



print((max(ans)))

for i in ans:

    print(i)

        

import sys

from collections import deque

readline = sys.stdin.buffer.readline

def even(n): return 1 if n%2==0 else 0

n = int(readline())

g = [[] for _ in range(n)] #隣接リスト

ab = []

for i in range(n-1):

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

    a,b = a-1,b-1

    ab.append((a,b))

    g[a].append(b)

    g[b].append(a)



root = 0

parent = [0]*n

deq = deque([root])

order = [root]



color = [-1]*n

deq = deque([root])

while deq:

    fr = deq.pop()

    ng = color[fr]

    c = 0

    for go in g[fr]:

        if go == parent[fr]:

            continue

        if c == ng:

            c += 1

        parent[go] = fr

        color[go] = c

        c += 1

        deq.append(go)

        order.append(go)

rank = [0]*n

for i,j in enumerate(order):

    rank[j] = i

print((max(color)+1))

for a,b in ab:

    if rank[a] < rank[b]:

        print((color[b]+1))

    else:

        print((color[a]+1))
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
AB = [list(map(int, readline().split())) for i in range(N - 1)]
graph = [[] for _ in range(N + 1)]  # 隣接リスト
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)
# 親のノードに子を入れてくdfs
stack = [1]
parent = [0] * (N + 1)
order = []
while stack:
    x = stack.pop()
    order.append(x)
    for i in graph[x]:
        if i == parent[x]:
            continue
        parent[i] = x
        stack.append(i)
# 各子の色を決めていく。
color = [-1] * (N + 1)
for x in order:
    ng = color[x]
    c = 1
    for y in graph[x]:
        if parent[x] == y:
            continue
        if c == ng:
            c += 1
        color[y] = c
        c += 1
ans = []
for a, b in AB:
    if parent[a] == b:  # 子の頂点の色を入れる
        ans.append(color[a])
    else:
        ans.append(color[b])
print((max(ans)))
for i in ans:
    print(i)

import sys
from collections import deque

readline = sys.stdin.buffer.readline


def even(n):
    return 1 if n % 2 == 0 else 0


n = int(readline())
g = [[] for _ in range(n)]  # 隣接リスト
ab = []
for i in range(n - 1):
    a, b = list(map(int, readline().split()))
    a, b = a - 1, b - 1
    ab.append((a, b))
    g[a].append(b)
    g[b].append(a)
root = 0
parent = [0] * n
deq = deque([root])
order = [root]
color = [-1] * n
deq = deque([root])
while deq:
    fr = deq.pop()
    ng = color[fr]
    c = 0
    for go in g[fr]:
        if go == parent[fr]:
            continue
        if c == ng:
            c += 1
        parent[go] = fr
        color[go] = c
        c += 1
        deq.append(go)
        order.append(go)
rank = [0] * n
for i, j in enumerate(order):
    rank[j] = i
print((max(color) + 1))
for a, b in ab:
    if rank[a] < rank[b]:
        print((color[b] + 1))
    else:
        print((color[a] + 1))

+from collections import deque -read = sys.stdin.buffer.read -readlines = sys.stdin.buffer.readlines -N = int(readline()) -AB = [list(map(int, readline().split())) for i in range(N - 1)] -graph = [[] for _ in range(N + 1)]  # 隣接リスト -for a, b in AB: -    graph[a].append(b) -    graph[b].append(a) -# 親のノードに子を入れてくdfs -stack = [1] -parent = [0] * (N + 1) -order = [] -while stack: -    x = stack.pop() -    order.append(x) -    for i in graph[x]: -        if i == parent[x]: -            continue -        parent[i] = x -        stack.append(i) -# 各子の色を決めていく。 -color = [-1] * (N + 1) -for x in order: -    ng = color[x] -    c = 1 -    for y in graph[x]: -        if parent[x] == y: + + +def even(n): +    return 1 if n % 2 == 0 else 0 + + +n = int(readline()) +g = [[] for _ in range(n)]  # 隣接リスト +ab = [] +for i in range(n - 1): +    a, b = list(map(int, readline().split())) +    a, b = a - 1, b - 1 +    ab.append((a, b)) +    g[a].append(b) +    g[b].append(a) +root = 0 +parent = [0] * n +deq = deque([root]) +order = [root] +color = [-1] * n +deq = deque([root]) +while deq: +    fr = deq.pop() +    ng = color[fr] +    c = 0 +    for go in g[fr]: +        if go == parent[fr]: -        color[y] = c +        parent[go] = fr +        color[go] = c -ans = [] -for a, b in AB: -    if parent[a] == b:  # 子の頂点の色を入れる -        ans.append(color[a]) +        deq.append(go) +        order.append(go) +rank = [0] * n +for i, j in enumerate(order): +    rank[j] = i +print((max(color) + 1)) +for a, b in ab: +    if rank[a] < rank[b]: +        print((color[b] + 1)) -        ans.append(color[b]) -print((max(ans))) -for i in ans: -    print(i) +        print((color[a] + 1))