#P6846. [CEOI 2019] Amusement Park
[CEOI 2019] Amusement Park
Description
There is a directed graph with vertices and edges. The graph has no multiple edges and no self-loops, and there is no cycle between any two vertices.
Now we want to reverse the direction of some edges so that the directed graph becomes acyclic.
You need to compute the answer after taking : for every valid way of reversing edges that makes the graph acyclic, take the number of edges that are reversed in this way; sum these numbers over all valid ways.
Input Format
The first line contains two integers .
The next lines each contain two integers , meaning there is a directed edge that starts at and ends at .
Output Format
Print one integer: the sum, over every way of reversing edges that makes the graph acyclic, of the number of edges that must be reversed, taken .
2 1
1 2
1
3 3
1 2
2 3
1 3
9
Hint
Sample Explanation
Sample 1 Explanation
There are two possible ways:
- Reverse the direction.
- Do not reverse the direction.
So the output is .
Sample 2 Explanation
There are six feasible ways:
So the output is .
Constraints
For of the testdata, it is guaranteed that , , , , for we have or , and the unordered pairs are all distinct.
The detailed subtask constraints and scores are as follows:
| Subtask ID | Constraint | Score |
|---|---|---|
| 1 | ||
| 2 | ||
| 3 | ||
| 4 | ||
| 5 | No additional constraints |
Note
This problem is translated from Central-European Olympiad in Informatics 2019 Day 2 T1 Amusement Park。
Translated by ChatGPT 5
京公网安备 11011102002149号