Problem Statement
You are given a simple connected undirected graph with $N$ vertices and $M$ edges, where the vertices are numbered $1$ to $N$ and the edges are numbered $1$ to $M$. Edge $i$ connects vertex $u_i$ and vertex $v_i$ in both directions.
Initially, there is a piece A on vertex $S$ and a piece B on vertex $T$. Here, $S$ and $T$ are given as input.
You may perform the following operation any number of times in any order:
- Choose either piece A or piece B, and move it from its current vertex to an adjacent vertex via an edge. However, you cannot make a move that results in both pieces ending up on the same vertex.
Your goal is to reach the state in which piece A is on vertex $T$ and piece B is on vertex $S$.
Determine whether this is possible, and if it is, find the minimum number of operations required to achieve it.
Constraints
$2 \le N \le 2\times 10^5$$\displaystyle N-1 \le M \le \min\left(\frac{N(N-1)}{2},\,2\times 10^5\right)$$1 \le u_i < v_i \le N$- The given graph is simple and connected.
$1 \le S, T \le N$$S \neq T$- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M S T
u_1 v_1
u_2 v_2
\vdots
u_M v_M
Output
If it is impossible to achieve the goal, print -1.
If it is possible, print the minimum number of operations required.
样例
4 4 3 4
2 4
1 4
3 4
2 3
3
2 1 1 2
1 2
-1
5 6 3 5
1 2
2 3
1 5
2 4
1 3
2 5
4
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。