N = gets.to_i
G = Array.new(N){[]} # 隣接リスト
C = Array.new(N-1) # 辺の色
M = Array.new(N) # 訪問済チェック

(N-1).times do |i|
  a,b = gets.split.map{|v|v.to_i - 1}
  G[a] << [b, i] # next vertex, edge
  G[b] << [a, i] # next vertex, edge
end

D = G.map(&:size).max

Q = [[0, -1]] # vertex, prev color
while Q.size > 0
  v,c = Q.pop
  M[v] = true
  color = (c + 1) % D
  G[v].each do |(nv,e)|
    next if M[nv]
    C[e] = color
    Q << [nv, color]
    color = (color + 1) % D
  end
end

puts D
C.each do |c|
  puts c+1
end