n = gets.to_i
edge = (n-1).times.map{gets.split.map(&:to_i)}
vert = (0..n).map{[]}

edge.each{|i|
  vert[i[0]]<<i
  vert[i[1]]<<i
}
p k = vert.map(&:size).max
vert.each{|edges|
  color = [*1..k]
  edges.each{|e|
    if e[2]
      color.delete(e[2])
    else
      e[2] = color.shift
    end
  }
}
puts edge.map{|e|e[2]}