A15077 | Keshi in Search of AmShZ
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
AmShZ has traveled to Italy from Iran for the Thom Yorke concert. There are $n$ cities in Italy indexed from $1$ to $n$ and $m$ directed roads indexed from $1$ to $m$ . Initially, Keshi is located in the city $1$ and wants to go to AmShZ's house in the city $n$ . Since Keshi doesn't know the map of Italy, AmShZ helps him to see each other as soon as possible.
In the beginning of each day, AmShZ can send one of the following two messages to Keshi:
- AmShZ sends the index of one road to Keshi as a blocked road. Then Keshi will understand that he should never use that road and he will remain in his current city for the day.
- AmShZ tells Keshi to move. Then, Keshi will randomly choose one of the cities reachable from his current city and move there. (city $B$ is reachable from city $A$ if there's an out-going road from city $A$ to city $B$ which hasn't become blocked yet). If there are no such cities, Keshi will remain in his current city.Note that AmShZ always knows Keshi's current location.
AmShZ and Keshi want to find the smallest possible integer $d$ for which they can make sure that they will see each other after at most $d$ days. Help them find $d$ .
In the beginning of each day, AmShZ can send one of the following two messages to Keshi:
- AmShZ sends the index of one road to Keshi as a blocked road. Then Keshi will understand that he should never use that road and he will remain in his current city for the day.
- AmShZ tells Keshi to move. Then, Keshi will randomly choose one of the cities reachable from his current city and move there. (city $B$ is reachable from city $A$ if there's an out-going road from city $A$ to city $B$ which hasn't become blocked yet). If there are no such cities, Keshi will remain in his current city.Note that AmShZ always knows Keshi's current location.
AmShZ and Keshi want to find the smallest possible integer $d$ for which they can make sure that they will see each other after at most $d$ days. Help them find $d$ .
输入格式
The first line of the input contains two integers $n$ and $m$ $(2 \le n \le 2 \cdot 10^5, 1 \le m \le 2 \cdot 10^5)$ — the number of cities and roads correspondingly.
The $i$ -th line of the following $m$ lines contains two integers $v_i$ and $u_i$ $(1 \le v_i , u_i \le n,v_i \neq u_i)$ , denoting a directed road going from city $v_i$ to city $u_i$ .
It is guaranteed that there is at least one route from city $1$ to city $n$ . Note that there may be more than one road between a pair of cities in each direction.
The $i$ -th line of the following $m$ lines contains two integers $v_i$ and $u_i$ $(1 \le v_i , u_i \le n,v_i \neq u_i)$ , denoting a directed road going from city $v_i$ to city $u_i$ .
It is guaranteed that there is at least one route from city $1$ to city $n$ . Note that there may be more than one road between a pair of cities in each direction.
输出格式
Output the smallest possible integer $d$ to make sure that AmShZ and Keshi will see each other after at most $d$ days.
输入输出样例
输入 #1
2 1 1 2
输出 #1
1
输入 #2
4 4 1 2 1 4 2 4 1 4
输出 #2
2
输入 #3
5 7 1 2 2 3 3 5 1 4 4 3 4 5 3 1
输出 #3
4
In the first sample, it's enough for AmShZ to send the second type of message.
In the second sample, on the first day, AmShZ blocks the first road. So the only reachable city from city $1$ will be city $4$ . Hence on the second day, AmShZ can tell Keshi to move and Keshi will arrive at AmShZ's house.
It's also possible for AmShZ to tell Keshi to move for two days.
In the second sample, on the first day, AmShZ blocks the first road. So the only reachable city from city $1$ will be city $4$ . Hence on the second day, AmShZ can tell Keshi to move and Keshi will arrive at AmShZ's house.
It's also possible for AmShZ to tell Keshi to move for two days.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted