[Solution] Keshi in Search of AmShZ Codeforces Solution | Codeforces Problem Solution 2022
AmShZ has traveled to Italy from Iran for the Thom Yorke concert. There are cities in Italy indexed from to and directed roads indexed from to . Initially, Keshi is located in the city and wants to go to AmShZ's house in the city . 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 is reachable from city if there's an out-going road from city to city 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 for which they can make sure that they will see each other after at most days. Help them find .
The first line of the input contains two integers and — the number of cities and roads correspondingly.
The -th line of the following lines contains two integers and , denoting a directed road going from city to city .
It is guaranteed that there is at least one route from city to city . Note that there may be more than one road between a pair of cities in each direction.
Output the smallest possible integer to make sure that AmShZ and Keshi will see each other after at most days.
No comments:
Post a Comment