N = gets.to_i
graph = N.times.map{ [] }
$<.each_with_index{|s, i|
  from, to = s.split.map(&:to_i).map &:pred
  graph[from] << [i, to]
  graph[to] << [i, from]
}


start = graph.index(graph.max_by &:size)
ans = [0] * (N - 1)

st = [start]
while !st.empty?
  from = st.pop
  color = 0
  used_colors = graph[from].map{|idx, to| ans[idx] }.select{|color| color != 0 }
  graph[from].each{|idx, to|
    next if ans[idx] != 0
    color += 1
    color += 1 while used_colors.include?(color)
    ans[idx] = color
    st << to
  }
end

p ans.max
p *ans
