N = gets.to_i
EDGES = (N-1).times.map { gets.split.map(&:to_i) }

nodes = {}
EDGES.each_with_index do |edge, i|
  nodes[edge[0]] ||= []
  nodes[edge[0]] << {edge: i, node: edge[1]}
  nodes[edge[1]] ||= []
  nodes[edge[1]] << {edge: i, node: edge[0]}
end

max_edges = 0
colors = {}

search_nodes = []
current_node = EDGES[0][0]
while current_node
  edges = nodes[current_node].size
  max_edges = edges if max_edges < edges

  used_colors = {}
  nodes[current_node].each do |edge|
    used_colors[colors[edge[:edge]]] = true if colors[edge[:edge]]
  end

  cur_color = 1
  nodes[current_node].each do |edge|
    next if colors[edge[:edge]]
    cur_color += 1 while used_colors[cur_color]
    colors[edge[:edge]] = cur_color
    search_nodes << edge[:node]

    cur_color += 1
  end

  current_node = search_nodes.pop
end

puts max_edges
0.upto(N-2) do |i|
  puts colors[i]
end