309524: CF1693C. Keshi in Search of AmShZ

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Keshi in Search of AmShZ

题意翻译

AmShZ已经从伊朗前往意大利参加托姆·约克音乐会。意大利有 $n$ 座城市,编号为 $1$ ~ $n$ , $m$ 条定向道路编号为 $1$ ~ $m$ $(2 \le n \le 2 \cdot 10^5, 1 \le m \le 2 \cdot 10^5)$ 。起初,Keshi位于1号城市,他想去AmShZ在 $n$ 市的家。由于Keshi不知道意大利地图,AmShZ要帮助他尽快见到自己。 在每天开始时,AmShZ可以向Keshi发送以下两条消息之一: 1.AmShZ将一条道路的编号作为阻塞道路发送给Keshi。然后,Keshi会明白,他永远不应该走这条路,他将留在他目前的城市的一天。 2.AmShZ告诉Keshi离开。然后,Keshi将随机选择一个可以从当前城市到达的城市,并搬到那里。(如果从 $A$ 市到 $B$ 市有一条出口道路尚未堵塞,则可以从 $A$ 市到达 $B$ 市)。如果没有这样的城市,Keshi将留在他现在的城市。注意,AmShZ总是知道Keshi的当前位置。 AmShZ和Keshi希望找到尽可能小的整数 $d$ ,使得他们可以确保在最多 $d$ 天之后彼此见面。帮助他们找到 $d$ 。

题目描述

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

输入输出格式

输入格式


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.

输出格式


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.

Input

题意翻译

AmShZ已经从伊朗前往意大利参加托姆·约克音乐会。意大利有 $n$ 座城市,编号为 $1$ ~ $n$ , $m$ 条定向道路编号为 $1$ ~ $m$ $(2 \le n \le 2 \cdot 10^5, 1 \le m \le 2 \cdot 10^5)$ 。起初,Keshi位于1号城市,他想去AmShZ在 $n$ 市的家。由于Keshi不知道意大利地图,AmShZ要帮助他尽快见到自己。 在每天开始时,AmShZ可以向Keshi发送以下两条消息之一: 1.AmShZ将一条道路的编号作为阻塞道路发送给Keshi。然后,Keshi会明白,他永远不应该走这条路,他将留在他目前的城市的一天。 2.AmShZ告诉Keshi离开。然后,Keshi将随机选择一个可以从当前城市到达的城市,并搬到那里。(如果从 $A$ 市到 $B$ 市有一条出口道路尚未堵塞,则可以从 $A$ 市到达 $B$ 市)。如果没有这样的城市,Keshi将留在他现在的城市。注意,AmShZ总是知道Keshi的当前位置。 AmShZ和Keshi希望找到尽可能小的整数 $d$ ,使得他们可以确保在最多 $d$ 天之后彼此见面。帮助他们找到 $d$ 。

Output

**题意翻译**

AmShZ已经从伊朗前往意大利参加托姆·约克音乐会。意大利有 $ n $ 座城市,编号为 $ 1 $ ~ $ n $ , $ m $ 条定向道路编号为 $ 1 $ ~ $ m $ $(2 \le n \le 2 \cdot 10^5, 1 \le m \le 2 \cdot 10^5)$ 。起初,Keshi位于1号城市,他想去AmShZ在 $ n $ 市的家。由于Keshi不知道意大利地图,AmShZ要帮助他尽快见到自己。

在每天开始时,AmShZ可以向Keshi发送以下两条消息之一:

1. AmShZ将一条道路的编号作为阻塞道路发送给Keshi。然后,Keshi会明白,他永远不应该走这条路,他将留在他目前的城市的一天。

2. AmShZ告诉Keshi离开。然后,Keshi将随机选择一个可以从当前城市到达的城市,并搬到那里。(如果从 $ A $ 市到 $ B $ 市有一条出口道路尚未堵塞,则可以从 $ A $ 市到达 $ B $ 市)。如果没有这样的城市,Keshi将留在他现在的城市。注意,AmShZ总是知道Keshi的当前位置。

AmShZ和Keshi希望找到尽可能小的整数 $ d $ ,使得他们可以确保在最多 $ d $ 天之后彼此见面。帮助他们找到 $ d $ 。

**题目描述**

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 outgoing 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 $ .

**输入输出格式**

**输入格式**

第一行包含两个整数 $ n $ 和 $ m $ $ (2 \le n \le 2 \cdot 10^5, 1 \le m \le 2 \cdot 10^5) $ — 城市数量和道路数量。

接下来的 $ m $ 行,每行包含两个整数 $ v_i $ 和 $ u_i $ $ (1 \le v_i , u_i \le n, v_i \neq u_i) $ ,表示从城市 $ v_i $ 到城市 $ u_i $ 的有向道路。

保证从城市 $ 1 $ 到城市 $ n $ 至少有一条路线。注意,每对城市之间可能有多条双向道路。

**输出格式**

输出最小的整数 $ d $ ,以确保AmShZ和Keshi在最多 $ d $ 天后见面。

**输入输出样例**

**输入样例 #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
```**题意翻译** AmShZ已经从伊朗前往意大利参加托姆·约克音乐会。意大利有 $ n $ 座城市,编号为 $ 1 $ ~ $ n $ , $ m $ 条定向道路编号为 $ 1 $ ~ $ m $ $(2 \le n \le 2 \cdot 10^5, 1 \le m \le 2 \cdot 10^5)$ 。起初,Keshi位于1号城市,他想去AmShZ在 $ n $ 市的家。由于Keshi不知道意大利地图,AmShZ要帮助他尽快见到自己。 在每天开始时,AmShZ可以向Keshi发送以下两条消息之一: 1. AmShZ将一条道路的编号作为阻塞道路发送给Keshi。然后,Keshi会明白,他永远不应该走这条路,他将留在他目前的城市的一天。 2. AmShZ告诉Keshi离开。然后,Keshi将随机选择一个可以从当前城市到达的城市,并搬到那里。(如果从 $ A $ 市到 $ B $ 市有一条出口道路尚未堵塞,则可以从 $ A $ 市到达 $ B $ 市)。如果没有这样的城市,Keshi将留在他现在的城市。注意,AmShZ总是知道Keshi的当前位置。 AmShZ和Keshi希望找到尽可能小的整数 $ d $ ,使得他们可以确保在最多 $ d $ 天之后彼此见面。帮助他们找到 $ d $ 。 **题目描述** 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 outgoing 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 $ . **输入输出格式** **输入格式** 第一行包含两个整数 $ n $ 和 $ m $ $ (2 \le n \le 2 \cdot 10^5, 1 \le m \le 2 \cdot 10^5) $ — 城市数量和道路数量。 接下来的 $ m $ 行,每行包含两个整数 $ v_i $ 和 $ u_i $ $ (1 \le v_i , u_i \le n, v_i \neq u_i) $ ,表示从城市 $ v_i $ 到城市 $ u_i $ 的有向道路。 保证从城市 $ 1 $ 到城市 $ n $ 至少有一条路线。注意,每对城市之间可能有多条双向道路。 **输出格式** 输出最小的整数 $ d $ ,以确保AmShZ和Keshi在最多 $ d $ 天后见面。 **输入输出样例** **输入样例 #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 ```

加入题单

算法标签: