n = gets.to_i
a = Array.new
(n - 1).times do |i|
    a[i] = gets.split.map(&:to_i)
end
rel = Array.new(n) { Array.new(n, 0) }
a.each do |aa|
    rel[aa[0] - 1][aa[1] - 1] = 1
end

def bfs(rel, s, w)
    max = 0
    q = [[s, 0]]
    while q.size > 0
        i, c = q.shift
        next_color = 0
        count = 0
        count += 1 if i != 0
        (i + 1).upto(w - 1) do |j|
            next if rel[i][j] == 0
            count += 1
            next_color += 1
            next_color += 1 if next_color == c
            q.push([j, next_color])
            rel[i][j] = next_color
        end
        max = count if count > max
    end
    return max
end

def pp(rel)
    rel.each do |r|
        r.each do |c|
            print c
        end
        puts
    end
    puts
end

max = bfs(rel, 0, n)

puts max
a.each do |aa|
    puts rel[aa[0] - 1][aa[1] - 1]
end