#P5480. [BJOI2015] 回家的路【征集spj】
[BJOI2015] 回家的路【征集spj】
Description
Xiaoqiang and Amoeba are good friends. Connecting Beijing and Xiaoqiang's hometown is a complicated railway network. There are stations in total, and between stations there are undirected railways of different lengths. Each time Xiaoqiang goes home, he randomly chooses one path among all shortest paths.
There is a railway in front of Amoeba's house. Without changing the shortest-path distance from Beijing to Xiaoqiang's hometown, Amoeba wants to add one directed railway of length to the network, so that the probability that Xiaoqiang passes through the railway in front of Amoeba's house is as large as possible. Please output this maximum probability.
Constraints
. It is guaranteed that no matter how you add the edge, the number of shortest paths between any two nodes in the graph will not exceed .
Input Format
The first line contains three positive integers and , representing the number of stations, the number of railways, and the length of the new railway. Stations are numbered from to . Beijing is node , and Xiaoqiang's hometown is node .
The next lines each contain three positive integers , indicating an undirected railway connecting stations and with length .
The first of these lines describes the railway in front of Amoeba's house. There may be multiple railways between the same pair of nodes. It is also possible that , i.e., a self-loop. The new railway you build may overlap an existing railway, and it may also be a self-loop. Nodes and are guaranteed to be connected.
Output Format
Output one line with two positive integers , meaning that you build a directed railway from to . Your construction is accepted if the difference between the probability that Xiaoqiang passes through the target railway under your plan and the standard answer is at most .
// Note: This problem lacks an , so please submit with caution.
3 3 1
1 2 1
2 3 1
1 3 2
2 3
Hint
After adding an edge, there are shortest paths in total. The probability that Xiaoqiang passes in front of Amoeba's house changes from to .
Translated by ChatGPT 5
京公网安备 11011102002149号