#P6777. [NOI2020] 翻修道路【数据有误】
[NOI2020] 翻修道路【数据有误】
Description
Country C contains cities, connected by undirected roads. The cities are numbered from to , and the roads are numbered from to . Road connects cities and , and its length is meters. Using these roads, starting from any city in Country C, one can reach all other cities.
People in Country C like traveling along cycles, but they do not like passing through too many roads, so the roads in Country C are built in a very special way. More specifically, for a simple cycle that passes through roads (i.e. a cycle that visits no repeated city except the starting city), it can be written as $c_{1} \rightarrow c_{2} \rightarrow \cdots \rightarrow c_{l} \rightarrow c_{1}$ (where for all , cities and are connected by a road; cities and are connected by a road; and for all , ). If , then the roads in Country C satisfy the following condition:
- There exist two non-adjacent cities , on the cycle such that there is a road directly connecting them. That is, there exists such that , and are not simultaneously and , and there is a road directly connecting cities and .
Now Country C has a new renovation plan. It needs to find a path between cities and to renovate. During the renovation, all roads on the path will be blocked. To ensure people’s daily life, Country C hopes that while renovating this path, using the remaining roads (i.e. the roads not included in the renovation path) can still satisfy: starting from any city in Country C, one can still reach all other cities.
Country C has found you, a master engineer. Please help Country C find a renovation path that satisfies the above requirements, and make the total length of the path as small as possible。
Input Format
The first line contains two integers , , representing the number of cities and the number of roads.
The next lines each contain three integers , , , representing the two endpoints of each road and its length.
The testdata guarantees that each road connects two different cities, i.e. .
The last line contains two integers , , representing the two endpoints of the path to be renovated.
Output Format
Output a single integer in one line, representing the minimum total length of a renovation path that satisfies the requirements.
If there is no path that satisfies the requirements, output one integer in one line.
4 5
1 2 1
2 3 1
3 4 1
1 3 5
2 4 6
1 4
6
2 1
1 2 1
1 2
-1
Hint
Explanation for Sample 1
The path is the shortest path (by total length) between cities and , but it does not satisfy the requirement.
The path satisfies the requirement, with length .
The path satisfies the requirement, with length .
Other than the two paths above, there is no other path that satisfies the requirement.
Sample 3
See road/road3.in and road/road3.ans in the contestant directory. This sample has the same constraints as test points .
Sample 4
See road/road4.in and road/road4.ans in the contestant directory. This sample has the same constraints as test points .
Sample 5
See road/road5.in and road/road5.ans in the contestant directory. This sample has the same constraints as test points .
Sample 6
See road/road6.in and road/road6.ans in the contestant directory. This sample has the same constraints as test points .
Constraints
For all test points: , , .
, , , and it is guaranteed that for any two roads, their endpoints are not both the same.
It is guaranteed that the given roads satisfy the property described in the second paragraph of the statement.
The detailed limits for each test point are shown in the table below:
| Test Point ID | Special Constraint | ||
|---|---|---|---|
| None | |||
| None |
Special constraint A: All roads have the same length.
Special constraint B: All roads with form exactly one path from to , and for every other road with , the distance between its two endpoints along this path is .
Translated by ChatGPT 5
京公网安备 11011102002149号