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
}
def dfs n,parent
  children = Vert[n].reject{|e|e[2]}
  color_max = children.size+1
  colors = [*1..parent-1,*parent+1..color_max]
  children.zip(colors){|child,color|
    child[2] = color
    if child[0] == n
      dfs child[1],color
    else
      dfs child[0],color
    end
  }
end

p k = Vert.map(&:size).max
dfs 1,0
puts Edge.map{|e|e[2]}