#P5603. 小 C 与桌游
小 C 与桌游
Background
Little C is a high school student who loves board games. Now he is stuck on a board game. Please help him.
Problem Description
The map of this board game can be seen as a directed acyclic graph with vertices and edges (not necessarily connected). Little C walks on this map. Little C can walk to a vertex if and only if all vertices that can reach this vertex have already been visited by Little C. Little C will visit every vertex exactly time, and which vertices he can visit does not depend on his current position (that is, he may visit a vertex that has no edge connected to his current vertex, as long as the condition above is satisfied).
Each time Little C visits a vertex whose label is larger than all previously visited vertices, he has probability to get chip from the opponent, and probability to give the opponent chip. Initially, both sides have chips.
Little C’s luck changes a lot, so he wants you to compute:
- In the best case, i.e. every time he can get a chip from the opponent, the number of chips he can obtain with an optimal walking strategy.
- In the worst case, i.e. every time the opponent can get a chip from him, the number of chips he will lose with an optimal walking strategy.
Input Format
The first line contains two positive integers .
The next lines each contain two positive integers , meaning there is a directed edge on the map. Multiple edges may exist.
Output Format
Output two lines, each containing one positive integer. The first line is the number of chips Little C can get in the best case. The second line is the number of chips Little C will lose in the worst case.
3 2
1 2
1 3
3
2
Hint
Sample Explanation
In the best case, the walking order is . In the worst case, the walking order is .
Scoring
For each test case:
- If your output format is wrong, or both lines are incorrect, you will get points.
- If your first line is correct and the second line is wrong, or the second line is correct and the first line is wrong, you will get of the points for this test case.
- Otherwise, you will get of the points for this test case.
Constraints
For of the testdata, .
For of the testdata, .
For of the testdata, , .
Translated by ChatGPT 5