n = gets.chomp.to_i
#n,k,q = gets.chomp.split.collect{ |item| item.to_i}
#s = gets.chomp

$result = [0]
$minl = []
hash = Hash.new()
max = 0
maxn = []
$list = []
(n-1).times do |ni|
  ai,bi = gets.chomp.split.collect{ |item| item.to_i}
  hash[ai] ||= []
  hash[bi] ||= []
  hash[ai] << [ni+1,ai,bi]
  hash[bi] << [ni+1,bi,ai]
  $list << (ni+1)
  $result << 0
end
$list << n
$result << 0

arr = hash.sort{|(k1, v1), (k2, v2)| v2.size <=> v1.size }
k = arr[0][1].size
ki = 1
arr[0][1].each do |one|
  $result[one[0]] = ki
  ki += 1
end
$list.delete(arr[0][0])
#
(n+1).times do |ki|
  $minl[ki] = [*1..k]
end

def setL(hash,i)
  return unless $list.include?(i)
  $list.delete(i)
  hash[i].each do |one|
    if $result[one[0]] == 0
      kk = $minl[i].shift
      $result[one[0]] = kk
      $minl[one[2]].delete(kk)
      setL(hash,one[2])
    end
  end
end

arr[0][1].each do |one|
  setL(hash,one[2])
end


###########
puts k
1.upto(n-1) do |ni|
  puts $result [ni]
end
