import sys

sys.setrecursionlimit(10 ** 7)

N = int(eval(input()))

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



for i in range(N-1):

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

  E[a].append((b, i))

  E[b].append((a, i))

  

K = max(len(e) for e in E)  # 使用する色の最大数

print(K)



ans = [-1]*(N-1)

def dfs(v=1, p=0, p_col=-1):

  col = 1

  for u, idx in E[v]:

    if u == p: continue # 親だったらスキップ

    if col == p_col: col += 1 # 親とつながっている辺の色は使わない

    ans[idx] = col

    dfs(u, v, col)

    col += 1

dfs()

print(("\n".join(map(str, ans))))

      
import sys

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read 

inp = sys.stdin.buffer.readline

def inpS(): return inp().rstrip().decode()

readlines = sys.stdin.buffer.readlines 



from collections import deque



N = int(inp())

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

nextEdege  = []



for _ in range(N-1):

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

  graph[a].append(b)  

  nextEdege.append(b)

  

q = deque([1]) # 頂点1から幅優先探索

color = [0]*(N+1)

while q:

  v = q.popleft()

  c = 1

  for u in graph[v]:

    if c == color[v]:

      c += 1

    color[u] = c

    c += 1

    q.append(u)

    

print((max(color)))    

for b in nextEdege:

  print((color[b]))

  



  
import sys

sys.setrecursionlimit(10**7)
N = int(eval(input()))
E = [[] for _ in range(N + 1)]
for i in range(N - 1):
    a, b = list(map(int, input().split()))
    E[a].append((b, i))
    E[b].append((a, i))
K = max(len(e) for e in E)  # 使用する色の最大数
print(K)
ans = [-1] * (N - 1)


def dfs(v=1, p=0, p_col=-1):
    col = 1
    for u, idx in E[v]:
        if u == p:
            continue  # 親だったらスキップ
        if col == p_col:
            col += 1  # 親とつながっている辺の色は使わない
        ans[idx] = col
        dfs(u, v, col)
        col += 1


dfs()
print(("\n".join(map(str, ans))))

import sys

sys.setrecursionlimit(10**7)
read = sys.stdin.buffer.read
inp = sys.stdin.buffer.readline


def inpS():
    return inp().rstrip().decode()


readlines = sys.stdin.buffer.readlines
from collections import deque

N = int(inp())
graph = [[] for _ in range(N + 1)]
nextEdege = []
for _ in range(N - 1):
    a, b = list(map(int, inp().split()))
    graph[a].append(b)
    nextEdege.append(b)
q = deque([1])  # 頂点1から幅優先探索
color = [0] * (N + 1)
while q:
    v = q.popleft()
    c = 1
    for u in graph[v]:
        if c == color[v]:
            c += 1
        color[u] = c
        c += 1
        q.append(u)
print((max(color)))
for b in nextEdege:
    print((color[b]))

-N = int(eval(input())) -E = [[] for _ in range(N + 1)] -for i in range(N - 1): -    a, b = list(map(int, input().split())) -    E[a].append((b, i)) -    E[b].append((a, i)) -K = max(len(e) for e in E)  # 使用する色の最大数 -print(K) -ans = [-1] * (N - 1) +read = sys.stdin.buffer.read +inp = sys.stdin.buffer.readline -def dfs(v=1, p=0, p_col=-1): -    col = 1 -    for u, idx in E[v]: -        if u == p: -            continue  # 親だったらスキップ -        if col == p_col: -            col += 1  # 親とつながっている辺の色は使わない -        ans[idx] = col -        dfs(u, v, col) -        col += 1 +def inpS(): +    return inp().rstrip().decode() -dfs() -print(("\n".join(map(str, ans)))) +readlines = sys.stdin.buffer.readlines +from collections import deque + +N = int(inp()) +graph = [[] for _ in range(N + 1)] +nextEdege = [] +for _ in range(N - 1): +    a, b = list(map(int, inp().split())) +    graph[a].append(b) +    nextEdege.append(b) +q = deque([1])  # 頂点1から幅優先探索 +color = [0] * (N + 1) +while q: +    v = q.popleft() +    c = 1 +    for u in graph[v]: +        if c == color[v]: +            c += 1 +        color[u] = c +        c += 1 +        q.append(u) +print((max(color))) +for b in nextEdege: +    print((color[b]))