#P2002. 消息扩散
消息扩散
Description
There are cities connected by one-way roads. Messages spread along the roads. Given cities and the roads between them, ask for the minimum number of cities where you need to initially publish the message so that all cities receive it.
Input Format
The first line contains two integers , meaning cities and directed roads. In the next lines, each line contains two integers , indicating there is a road from to . Multiple edges and self-loops are allowed.
Output Format
Output a single integer, the minimum number of cities where the message must be published.
5 4
1 2
2 1
2 3
5 1
2
Hint
-
Sample Explanation #1
In the sample, publish the message in cities and . -
Constraints
For of the testdata, .
For of the testdata, .
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号