3 人解决,8 人已尝试。
4 份提交通过,共有 13 份提交。
8.7 EMB 奖励。
单点时限: 2.0 sec
内存限制: 256 MB
The airline company NCPC Airways has flights to and from
Recently many of NCPC Airways frequent flyers have complained that they have had to change flights too often to get to their final destination. Since NCPC Airways doesn’t want to loose their customers to other airline companies, but still keep the nice property of their flights, they have decided to cancel one of their current flights and replace it with another flight. Help the company by writing a program which finds the best flight to cancel and the best new flight to add so that the maximum number of flight changes a passenger might have to make when travelling between any pair of cities in which NCPC Airways operates is minimized.
The input will be constructed so that it is always possible to improve the maximum number of flight changes needed.
The first line in the input contains the integer
The output should consist of three lines. The first line should contain an integer, the minimum number of flights needed to take when travelling between any pair of cities after changing one of the flights. The second line should contain two integers, specifying the two cities between which the flight should be canceled. The third line should contain two integers, specifying the two cities where a new flight should be added.
If there are more than one optimal solution, any one of them will be accepted.
4 1 2 2 3 3 4
2 3 4 2 4
14 1 2 1 8 2 3 2 4 8 9 8 10 8 11 4 5 4 6 4 7 10 12 10 13 13 14
5 1 8 2 10
3 人解决,8 人已尝试。
4 份提交通过,共有 13 份提交。
8.7 EMB 奖励。