CF1693C.Keshi in Search of AmShZ

普及/提高-

通过率:0%

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 .

输入格式

The first line of the input contains two integers nn and mm (2n2105,1m2105)(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 (1vi,uin,viui)(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.

输出格式

Output the smallest possible integer dd to make sure that AmShZ and Keshi will see each other after at most dd 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 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.

首页