CF1693C.Keshi in Search of AmShZ

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

AmShZ has traveled to Italy from Iran for the Thom Yorke concert. There are nn cities in Italy indexed from 11 to nn and mm directed roads indexed from 11 to mm. Initially, Keshi is located in the city 11 and wants to go to AmShZ's house in the city nn. 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 BB is reachable from city AA if there's an out-going road from city AA to city BB 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 dd for which they can make sure that they will see each other after at most dd days. Help them find dd.

AmShZ 为了观看 Thom Yorke 的演唱会,从伊朗来到了意大利。意大利共有 nn 座城市,编号从 11 到 nn,以及 mm 条有向道路,编号从 11 到 mm。初始时,Keshi 位于城市 11,他希望前往位于城市 nn 的 AmShZ 家中。由于 Keshi 不熟悉意大利的地图,AmShZ 帮助他尽快与自己见面。

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

  • AmShZ 向 Keshi 发送一条被封锁道路的编号。随后,Keshi 将明白他永远不应使用该道路,并在当天停留在当前所在城市。
  • AmShZ 告知 Keshi 移动。随后,Keshi 将随机选择一个从其当前城市出发、可通过的(即尚未被封锁的)有向道路所能到达的城市,并移动到该城市。(若存在从城市 AA 到城市 BB 的一条尚未被封锁的出边,则称城市 BB 从城市 AA 可达。)若不存在这样的城市,Keshi 将停留在当前城市。

注意:AmShZ 始终知晓 Keshi 当前所处的位置。

AmShZ 和 Keshi 希望找到最小的正整数 dd,使得他们能够确保在至多 dd 天内彼此相见。请帮助他们求出 dd。

输入格式

The first line of the input contains two integers nn and mm (2≤n≤2⋅105,1≤m≤2⋅105)(2 \le n \le 2 \cdot 10^5, 1 \le m \le 2 \cdot 10^5) — the number of cities and roads correspondingly.

The ii-th line of the following mm lines contains two integers viv_i and uiu_i (1≤vi,ui≤n,vi≠ui)(1 \le v_i , u_i \le n,v_i \neq u_i), denoting a directed road going from city viv_i to city uiu_i.

It is guaranteed that there is at least one route from city 11 to city nn. Note that there may be more than one road between a pair of cities in each direction.

输入的第一行包含两个整数 nn 和 mm(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5,1≤m≤2⋅1051 \le m \le 2 \cdot 10^5),分别表示城市的数量和道路的数量。

接下来的 mm 行中,第 ii 行包含两个整数 viv_i 和 uiu_i(1≤vi,ui≤n1 \le v_i , u_i \le n,且 vi≠uiv_i \neq u_i),表示一条从城市 viv_i 指向城市 uiu_i 的有向道路。

保证至少存在一条从城市 11 到城市 nn 的路径。注意:在每一对城市之间,每个方向上可能存在多条道路。

输出格式

Output the smallest possible integer dd to make sure that AmShZ and Keshi will see each other after at most dd days.

输出确保 AmShZ 和 Keshi 在至多 dd 天后相遇的最小可能整数 dd。

输入输出样例

  • 输入#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 11 will be city 44. 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.

在第一个样例中,AmShZ 只需发送第二种类型的消息即可。

在第二个样例中,第一天,AmShZ 封锁了第一条道路。因此,从城市 11 出发唯一可达的城市是城市 44。于是第二天,AmShZ 可以告诉 Keshi 移动,Keshi 将到达 AmShZ 的住所。

此外,AmShZ 也可以连续两天都告诉 Keshi 移动。

输入解题思路,AI测评打分。不知道怎么写?

首页