#P5683. [CSP-J 2019 江西] 道路拆除
[CSP-J 2019 江西] 道路拆除
Description
Country A has cities, numbered from . City is the capital of Country A. The cities are connected by undirected roads, and the time to travel along each road is unit of time.
Now Country A plans to remove some impractical roads to reduce maintenance costs, but it also needs to ensure that the main routes are not affected. Therefore, after the road removals, using the remaining roads, starting from the capital of Country A, it must be possible to reach city and city , and the shortest times required must be no more than and , respectively (note that these are two independent conditions with no relation to each other; that is, you do not need to go to first and then to ).
Country A asks you to compute, under the above conditions, the maximum number of roads that can be removed. If the above conditions can never be satisfied, output .
Input Format
The first line contains two positive integers , representing the number of cities and the number of roads.
The next lines each contain two positive integers , representing a road connecting node and node .
The last line contains four integers, which are .
Output Format
Only one line containing one integer, representing the answer.
5 6
1 2
2 3
1 3
3 4
4 5
3 5
5 3 4 3
3
3 2
1 2
2 3
2 2 3 1
-1
Hint
Constraints
For of the testdata, .
For another of the testdata, and .
For another of the testdata, .
For of the testdata, , , , .
Explanation of Sample
Remove three edges: , , .
Note: It is not necessary to keep the capital connected to nodes other than after the removal.
Explanation of Sample
Even if not a single edge is removed, the shortest time from the capital to node is already units of time.
testdata by @DYH060310
Translated by ChatGPT 5
京公网安备 11011102002149号