#P5683. [CSP-J 2019 江西] 道路拆除

[CSP-J 2019 江西] 道路拆除

Description

Country A has nn cities, numbered from 1n1 \sim n. City 11 is the capital of Country A. The cities are connected by mm undirected roads, and the time to travel along each road is 11 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 s1s_1 and city s2s_2, and the shortest times required must be no more than t1t_1 and t2t_2, respectively (note that these are two independent conditions with no relation to each other; that is, you do not need to go to s1s_1 first and then to s2s_2).

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 1-1.

Input Format

The first line contains two positive integers n,mn, m, representing the number of cities and the number of roads.

The next mm lines each contain two positive integers x,yx, y, representing a road connecting node xx and node yy.

The last line contains four integers, which are s1,t1,s2,t2s_1, t_1, s_2, t_2.

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 30%30\% of the testdata, n,m15n, m \le 15.
For another 20%20\% of the testdata, n100n \le 100 and m=n1m = n - 1.
For another 30%30\% of the testdata, s1=s2s_1 = s_2.
For 100%100\% of the testdata, 2n,m30002 \le n, m \le 3000, 1x,yn1 \le x, y \le n, 2s1,s2n2 \le s_1, s_2 \le n, 0t1,t2n0 \le t_1, t_2 \le n.

Explanation of Sample 11
Remove three edges: (1,2)(1,2), (2,3)(2,3), (3,4)(3,4).
Note: It is not necessary to keep the capital connected to nodes other than s1,s2s_1, s_2 after the removal.

Explanation of Sample 22
Even if not a single edge is removed, the shortest time from the capital to node 33 is already 22 units of time.

testdata by @DYH060310

Translated by ChatGPT 5