自动驾驶AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)There are $N$ planets and $M$ routes. The planets are numbered $1$ to $N$, and the routes are numbered $1$ to $M$.
有 $N$ 个行星和 $M$ 条航线。行星编号为 $1$ 到 $N$,航线编号为 $1$ 到 $M$。AI (CI翻译)
Route $i$ goes from planet $A_i$ to planet $B_i$. Each route is one-way.
航线 $i$ 从行星 $A_i$ 通往行星 $B_i$。每条航线都是单向的。AI (CI翻译)
A spaceship can perform the following two types of operations.
宇宙飞船可以执行以下两种操作。AI (CI翻译)
- Move, without consuming fuel, to the planet with the smallest number among the planets directly reachable by a route from the current planet.
- Choose any planet directly reachable by a route from the current planet, and move to the chosen planet, consuming
$1$unit of fuel.
- 不消耗燃料,移动到从当前行星出发、通过一条航线可以直接到达的行星中编号最小的行星。
- 从通过一条航线可以直接到达的行星中任选一个,移动到该行星,并消耗
$1$单位燃料。
Find the minimum amount of fuel the spaceship consumes to start from planet $S$ and arrive at planet $T$. If it is impossible to reach planet $T$, print $-1$ instead.
求宇宙飞船从行星 $S$ 出发并到达行星 $T$ 所消耗的最少燃料。如果无法到达行星 $T$,则输出 $-1$。AI (CI翻译)
Constraints
约束条件
AI (CI翻译)$2 \leq N \leq 2 \times 10^5$$1 \leq M \leq 2 \times 10^5$$1 \leq S,T \leq N$$S \neq T$$1 \leq A_i, B_i \leq N$$A_i \neq B_i$- All input values are integers.
$2 \leq N \leq 2 \times 10^5$$1 \leq M \leq 2 \times 10^5$$1 \leq S,T \leq N$$S \neq T$$1 \leq A_i, B_i \leq N$$A_i \neq B_i$- 所有输入值均为整数。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入从标准输入按以下格式给出:AI (CI翻译)
N M S T
A_1 B_1
\vdots
A_M B_M
N M S T
A_1 B_1
\vdots
A_M B_MAI (CI翻译)
Output
输出格式
AI (CI翻译)Print the answer.
输出答案。AI (CI翻译)
样例
7 10 2 1
2 5
2 4
4 2
4 3
3 1
3 5
3 6
5 6
6 1
6 7
1
7 10 2 7
2 5
2 4
4 2
4 3
3 1
3 5
3 6
5 6
6 1
6 7
2
2 1 1 2
2 1
-1
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。