n = gets.to_i
e = []

def max(x,y)
  return x > y ? x : y
end

done = []
(n+1).times {
  e << []
  done << false
}

e2 = []
(n-1).times { |i|
  a,b = gets.split.map {|x| x.to_i}
  e[a] << [b,i]
  e[b] << [a,i]
  e2 << [a,b,-1]
}
maxe = 0
ind = 0
e.each_with_index { |_e, index|
  if _e.size > maxe
    ind = index
    maxe = _e.size
  end
}

puts maxe



def paint(node, color, done, e, e2)
  cur_col = 1
  done[node] = true
  e[node].each_with_index { |v|
    dst = v[0]
    if (done[dst] == false)
      if cur_col == color
        cur_col += 1
      end
      e2[v[1]][2] = cur_col
      paint(dst, cur_col, done, e, e2)
      cur_col += 1
    end
  }
end

paint(ind, -1, done, e, e2)

e2.each { |v|
  puts v[2]
}
