Edge = Struct.new(:id, :to)
N = gets.to_i
G = Array.new(N + 1){ [] }
E = (1 ... N).map { gets.split.map(&:to_i) }
C = Array.new(N - 1, 0)
E.each_with_index do |(a,b),e|
  G[a] << Edge.new(e, b)
  G[b] << Edge.new(e, a)
end
d = (1 .. N).map{|i| G[i].size }.max

q = [[1, N, 0]] # node, parent_edge, parent_edge_color
until q.empty?
  v, pe, pec = q.shift
  c = 1
  G[v].inject(1) do |c, e|
    if e.id == pe
      c
    elsif c == pec
      C[e.id] = c + 1
      q.push([e.to, e.id, c + 1])
      c + 2
    else
      C[e.id] = c
      q.push([e.to, e.id, c])
      c + 1
    end
  end
end
puts d
puts C
