#P5603. 小 C 与桌游

    ID: 6347 远端评测题 1500ms 500MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划 DP贪心Special Judge拓扑排序洛谷月赛

小 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 nn vertices and mm 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 11 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 12\frac{1}{2} to get 11 chip from the opponent, and probability 12\frac{1}{2} to give the opponent 11 chip. Initially, both sides have 19198101919810 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 n,mn, m.

The next mm lines each contain two positive integers u,vu, v, meaning there is a directed edge (u,v)(u, v) 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 1231-2-3. In the worst case, the walking order is 1321-3-2.

Scoring

For each test case:

  • If your output format is wrong, or both lines are incorrect, you will get 00 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 40%40 \% of the points for this test case.
  • Otherwise, you will get 100%100 \% of the points for this test case.

Constraints

For 20%20\% of the testdata, 1n,m101 \le n, m \le 10.

For 40%40\% of the testdata, 1n,m20001 \le n, m \le 2000.

For 100%100\% of the testdata, 1n,m5×1051 \le n, m \le 5 \times 10^5, 1u,vn1 \le u, v \le n.

Translated by ChatGPT 5