#P11073. Game King
Game King
Problem Description
You have traveled to the world of Yu-Gi-Oh!, and now you are dueling against your opponent—a directed graph with vertices and edges.
Then I forgot what happened.
A true duelist believes everything is inevitable. To deal with the duel in front of you, you need to know how many vertices satisfy the following condition.
- For any vertex , it holds that either can reach or can reach (we consider that a vertex can reach itself).
Input Format
The first line contains two positive integers , representing the number of vertices and the number of edges in the given directed graph.
The next lines each contain two positive integers , denoting a directed edge .
Output Format
Output one integer in one line: the answer, i.e., how many vertices satisfy that every vertex can reach it or be reached from it.
4 4
1 2
1 3
2 4
3 4
2
Hint
Explanation for Sample 1
It can be proven that only vertices and satisfy the requirement.
Since vertex cannot reach vertex and also cannot be reached from vertex , vertices and do not satisfy the requirement.
Sample 2
See the attached files gameh2.in and gameh2.ans.
The constraints of this sample are the same as test point .
Sample 3
See the attached files gameh3.in and gameh3.ans.
The constraints of this sample are the same as test point .
Constraints
This problem has test points. The test points are not evenly distributed, and the score for each test point is as follows.
| Test Point ID | Score | ||
|---|---|---|---|
For all testdata, it is guaranteed that and .
For odd-numbered test points, it is guaranteed that the given graph has no cycles with more than distinct vertex.
Hint
The input and output size of this problem is large, so please use fast I/O.
Translated by ChatGPT 5