lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

def min_rest(a,b)
  for i in 1..N do
    if (a.include?(i) or b.include?(i)) == false then
      result = i
      break
    end
  end
  return result
end

N = lines[0][0]

accessible = []
for i in 1..N do
  accessible[i-1] = []
end
for i in 1..N-1 do
  from = lines[i][0]
  to = lines[i][1]
  accessible[from-1].push(to)
  accessible[to-1].push(from)
end

num_edge = []
for i in 1..N do
  num_edge[i-1] = accessible[i-1].length
end
max_edge = num_edge.max

num_color = max_edge
node_color = []
for i in 1..N do
  node_color[i-1] = []
end

edge_color = []
for i in 1..N-1 do
  edge_color[i-1] = 0
end

for i in 1..N-1 do
  from = lines[i][0]
  to = lines[i][1]
  color = min_rest(node_color[from-1], node_color[to-1])
  edge_color[i-1] = color
  node_color[from-1].push(color)
  node_color[to-1].push(color)
end
  
puts num_color
puts edge_color