#P1613. 跑路
跑路
Description
Xiao A’s job is not only tedious but also has strict rules: he must arrive at the company before every morning, otherwise his salary for the month will be zero. However, Xiao A has a bad habit of sleeping in. To save his salary, he bought a space “running” device that can run kilometers per second (where is any natural number). Of course, this machine stores values using longint, so the total running length cannot exceed maxlongint kilometers. The route from Xiao A’s home to the company can be modeled as a directed graph: Xiao A’s home is node , the company is node , and each edge has length one kilometer. Xiao A wants to wake up as late as possible every day, so he asks you to compute the minimum number of seconds he needs to reach the company. It is guaranteed that there is at least one path from to .
Input Format
The first line contains two integers , representing the number of nodes and the number of edges.
The next lines each contain two integers , indicating a directed edge from to .
Output Format
Output a single number on one line, representing the minimum number of seconds needed to reach the company.
4 4
1 1
1 2
2 3
3 4
1
Hint
【Sample Explanation】
, the total path length is kilometers, so using the running device once is enough.
【Constraints】
of the testdata satisfies that the optimal path length ;
of the testdata satisfies , , and the optimal path length maxlongint.
Translated by ChatGPT 5
京公网安备 11011102002149号