N=int(eval(input()))

E=[None]*(N-1)

EV=[[] for i in range(N)]

for i in range(N-1):

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

  a,b=a-1,b-1

  E[i]=[a,b]

  # 相手, 色, 回答出力順(-1は無視)

  EV[a].append([b,-1,i])

  EV[b].append([a,-1,-1])



ans=[0]*(N-1)

# visited=[False]*N



stack=[]

# 対象のノード, 親、親の色

stack.append([0,-1,0])

while stack:

  node=stack.pop()

  v=node[0]

  parent=node[1]

  parentcolor=node[2]

  childs=EV[v]

  color=1

  # visited[v]=True

  for i in range(len(childs)):

    child=childs[i]

    child_v=child[0]

    if child_v==parent:

      continue

    if color==parentcolor:

      color+=1

    childs[i][1]=color

    position=child[2]

    if position!=-1:

      ans[position]=color

    stack.append([child_v,v,color])

    color+=1

    

# answer

print((max(ans)))

for i in range(len(ans)):

  print((ans[i]))
# ある頂点で、子供に対して順に1,2,3...と辺の色を渡していく

# 親から来た色を持っておき、親から来た色と同色になったときはスキップして次の色を渡す

# グラフ構築の際に、辺の番号を持っておく



import sys

readline = sys.stdin.readline



N = int(readline())

G = [[] for i in range(N)]

for i in range(N - 1):

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

  G[a-1].append([b-1,i])

  G[b-1].append([a-1,i])

  

ans = [0 for i in range(N - 1)]

from collections import deque

# 頂点、親から来た色、親

q = deque([[0, 0, -1]])

while q:

  v,pcol,parent = q.popleft()

  cnt = 1

  for child in G[v]:

    if child[0] == parent:

      continue

    if cnt == pcol:

      cnt += 1

    ans[child[1]] = cnt

    q.append([child[0],cnt,v])

    cnt += 1



print((max(ans)))

for a in ans:

  print(a)
N = int(eval(input()))
E = [None] * (N - 1)
EV = [[] for i in range(N)]
for i in range(N - 1):
    a, b = list(map(int, input().split()))
    a, b = a - 1, b - 1
    E[i] = [a, b]
    # 相手, 色, 回答出力順(-1は無視)
    EV[a].append([b, -1, i])
    EV[b].append([a, -1, -1])
ans = [0] * (N - 1)
# visited=[False]*N
stack = []
# 対象のノード, 親、親の色
stack.append([0, -1, 0])
while stack:
    node = stack.pop()
    v = node[0]
    parent = node[1]
    parentcolor = node[2]
    childs = EV[v]
    color = 1
    # visited[v]=True
    for i in range(len(childs)):
        child = childs[i]
        child_v = child[0]
        if child_v == parent:
            continue
        if color == parentcolor:
            color += 1
        childs[i][1] = color
        position = child[2]
        if position != -1:
            ans[position] = color
        stack.append([child_v, v, color])
        color += 1
# answer
print((max(ans)))
for i in range(len(ans)):
    print((ans[i]))

# ある頂点で、子供に対して順に1,2,3...と辺の色を渡していく
# 親から来た色を持っておき、親から来た色と同色になったときはスキップして次の色を渡す
# グラフ構築の際に、辺の番号を持っておく
import sys

readline = sys.stdin.readline
N = int(readline())
G = [[] for i in range(N)]
for i in range(N - 1):
    a, b = list(map(int, readline().split()))
    G[a - 1].append([b - 1, i])
    G[b - 1].append([a - 1, i])
ans = [0 for i in range(N - 1)]
from collections import deque

# 頂点、親から来た色、親
q = deque([[0, 0, -1]])
while q:
    v, pcol, parent = q.popleft()
    cnt = 1
    for child in G[v]:
        if child[0] == parent:
            continue
        if cnt == pcol:
            cnt += 1
        ans[child[1]] = cnt
        q.append([child[0], cnt, v])
        cnt += 1
print((max(ans)))
for a in ans:
    print(a)

-N = int(eval(input())) -E = [None] * (N - 1) -EV = [[] for i in range(N)] +# ある頂点で、子供に対して順に1,2,3...と辺の色を渡していく +# 親から来た色を持っておき、親から来た色と同色になったときはスキップして次の色を渡す +# グラフ構築の際に、辺の番号を持っておく +import sys + +readline = sys.stdin.readline +N = int(readline()) +G = [[] for i in range(N)] -    a, b = list(map(int, input().split())) -    a, b = a - 1, b - 1 -    E[i] = [a, b] -    # 相手, 色, 回答出力順(-1は無視) -    EV[a].append([b, -1, i]) -    EV[b].append([a, -1, -1]) -ans = [0] * (N - 1) -# visited=[False]*N -stack = [] -# 対象のノード, 親、親の色 -stack.append([0, -1, 0]) -while stack: -    node = stack.pop() -    v = node[0] -    parent = node[1] -    parentcolor = node[2] -    childs = EV[v] -    color = 1 -    # visited[v]=True -    for i in range(len(childs)): -        child = childs[i] -        child_v = child[0] -        if child_v == parent: +    a, b = list(map(int, readline().split())) +    G[a - 1].append([b - 1, i]) +    G[b - 1].append([a - 1, i]) +ans = [0 for i in range(N - 1)] +from collections import deque + +# 頂点、親から来た色、親 +q = deque([[0, 0, -1]]) +while q: +    v, pcol, parent = q.popleft() +    cnt = 1 +    for child in G[v]: +        if child[0] == parent: -        if color == parentcolor: -            color += 1 -        childs[i][1] = color -        position = child[2] -        if position != -1: -            ans[position] = color -        stack.append([child_v, v, color]) -        color += 1 -# answer +        if cnt == pcol: +            cnt += 1 +        ans[child[1]] = cnt +        q.append([child[0], cnt, v]) +        cnt += 1 -for i in range(len(ans)): -    print((ans[i])) +for a in ans: +    print(a)