| Codeforces Round 1133 (Div. 2) |
|---|
| Finished |
Given a connected, undirected, simple graph $$$G$$$ with $$$n$$$ vertices and $$$m$$$ edges, define its meta-graph $$$f(G)$$$ as follows:
Given two vertices $$$w_x$$$ and $$$y_z$$$, determine the number of edges on the shortest path between them in $$$f(G)$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each test case contains the two integers $$$n$$$ and $$$m$$$ ($$$2\le n\le 2\cdot 10^5$$$, $$$n - 1 \le m\le \min\left(2\cdot 10^5, \frac{n(n-1)}{2}\right)$$$) — the number of vertices and the number of edges in $$$G$$$.
The second line contains four integers $$$w$$$, $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1\le w, x, y, z\le n$$$) — the start vertex $$$w_x$$$ and end vertex $$$y_z$$$, respectively.
The next $$$m$$$ lines each contain two integers $$$a$$$ and $$$b$$$ ($$$1\le a \lt b\le n$$$) — the edges of $$$G$$$. It is guaranteed that no edge appears more than once, and that $$$G$$$ is connected.
It is guaranteed that both the sum of $$$n$$$ and the sum of $$$m$$$ over all testcases are bounded by $$$2\cdot 10^5$$$.
For each test case, output a single integer: the number of edges on the shortest path from $$$w_x$$$ to $$$y_z$$$ in $$$f(G)$$$. We can show that at least one path between them always exists under the conditions of the problem.
33 21 1 3 31 22 34 41 1 4 11 22 33 41 42 11 1 1 11 2
620
In the first example, the shortest (and only) path is $$$1_1, 1_2, 2_1, 2_2, 2_3, 3_2, 3_3$$$.
The meta-graph for the first example. In the second example, the shortest path is $$$1_1, 1_4, 4_1$$$.
| Name |
|---|


