|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|1 초||512 MB||0||0||0||0.000%|
Prime Minister Louie, the democratically appointed top banana of the sovereign nation of orangutans, has a monkey on his back. His hairy subjects traditionally travel between locations by swinging from vine to vine along the forest superhighway. However, due to increasing traffic, there has been a dramatic increase of mid-air collisions and other forms of swinging accidents.
To improve travel safety, Louie has decided to replace the old vine-based transportation system by a new network of rope bridges. Two trees A and B along the highway will be connected by a rope bridge if all of the trees between A and B are strictly shorter than both A and B. If A and B are not connected by a bridge, a citizen travelling from A to B has to use multiple bridges, changing between bridges at some intermediate tree or trees between A and B (see Figure B.1). Note that a citizen travelling from A to B only does so by taking bridges leading towards B, never in the opposite direction.
Figure B.1: A solution to Sample Input 2 showing the bridges built. Travelling from tree 1 to 4 can be done using a single bridge. Travelling from tree 2 to 8 requires 4 bridges—the trip could be made using 3 bridges by going via tree 1, but citizens never travel away from their destination.
The trees tend to be very crowded, especially during rush hour, so changing between bridges can be frustrating enough to make you go ape. Therefore, Louie aims to minimise the number of bridges that the average traveller needs to use to get to their destination. All routes travelled along the highway are well understood and have been collected in the most recent jungle census. What remains is to design the tree layout along the forest superhighway, or more specifically, the heights of the trees.
Find out how to set the heights of the trees so that the total number of bridges used, summed over all journeys in the jungle census, is minimised.
The input consists of:
On the first line, output the minimum possible total number of bridges used.
On the next line, output a sequence of heights, in metres, of the trees that achieves this minimum. Your answer may only use integer tree heights between 1 and 109 (inclusive).
If there are multiple valid solutions, output any one of them.
4 3 1 3 2 4 1 4
4 4 2 1 3
10 9 2 3 1 8 8 4 6 4 1 4 1 4 1 4 5 9 5 10
12 5 1 3 4 5 1 1 2 3 4