n = gets.to_i
ans = [-1]*(n-1)
g = Array.new(n+1){[]}
(n-1).times do |i|
  a,b = gets.split.map(&:to_i)
  g[a] << [b,i]
  g[b] << [a,i]
end

color = 1
g.each do |a|
  color = [a.length, color].max
end

visited = [false]*(n+1)
visited[1] = true
que = [1]
while !que.empty?
  v = que.shift
  used = [false]*(color+1)
  g[v].each do |u,i|
    if ans[i] != -1
      used[ans[i]] = true
    else
      que << u if !visited[u]
      visited[u] = true
    end
  end
  #p [v, used]
  c = 1
  while !g[v].empty?
    t = g[v].shift
    next if ans[t[1]] != -1
    c += 1 while used[c]
    ans[t[1]] = c
    used[c] = true
    #p [v, t, c]
  end
end
p color
puts ans.join("\n")