n = gets.to_i
a = []
b = []
connect_vertex = Array.new(n+1,0)
g = Array.new(n+1).map{Array.new}
(n-1).times do |i|
  a[i], b[i] = gets.chomp.split(" ").map(&:to_i)
  g[a[i]].push(b[i])
  g[b[i]].push(a[i])
  connect_vertex[a[i]] += 1
  connect_vertex[b[i]] += 1
end
max = connect_vertex.max
puts max

ans = Array.new(n+1).map{Array.new}
dist = Array.new(g.length,-1)
dist[1] = 0
queue = [1]
visited = Array.new(n+1,0)
while !queue.empty?
  v = queue[0]
  queue.shift
  unko = 1
  g[v].each{|des|
    if dist[des] == -1
      dist[des] = dist[v] + 1
      if unko != visited[v]
        ans[v][des] = unko
        ans[des][v] = unko
        visited[des] = unko
        queue.push(des)
      else
        unko += 1
        ans[v][des] = unko
        ans[des][v] = unko
        visited[des] = unko
        queue.push(des)
      end
      unko += 1
    end
   }
end

(n-1).times do |i|
  puts ans[a[i]][b[i]]
end