N = gets.to_i
A,B = (N-1).times.map{gets.split.map(&:to_i)}.transpose
C=Array.new(N-1)
for i in 0..N-2
  list=[]
  for j in 0..(i-1)
    if A[j] == A[i] || A[j] == B[i] || B[j] == A[i] || B[j] == B[i]
      list.push(C[j])
    end
  end
  for k in 1..N-1
    if !list.include?(k)
      C[i] = k
      break
    end
  end
end
puts C.max,C