n = gets.to_i
as = []
bs = []

map = {}

(n-1).times {
	a,b = gets.split.map &:to_i
	as << a
	bs << b

	if map[a] == nil then
		map[a] = []
	end
	map[a] << b
	
	if map[b] == nil then
		map[b] = []
	end
	map[b] << a
}

max = map.each_value.map{ |x| x.size }.max

color = {}

current = [[1, 0]]
temp = nil

while current.size > 0
	next_current = []
	current.each{ |target, temp_color|
		map[target].each{ |node|
			if color[[target, node]] == nil then
				temp_color += 1
				if temp_color > max then
					temp_color -= max
				end
				next_current << [node, temp_color]
				color[[target, node]] = temp_color
				color[[node, target]] = temp_color
			end
		}
	}
	current = next_current
end

puts max

(0...n - 1).each{ |i|
	puts color[[as[i], bs[i]]]
}