#P4233. 射命丸文的笔记
射命丸文的笔记
Description
If a tournament contains a Hamiltonian cycle, then we call this tournament “worth recording.”
Choose uniformly at random from all “worth recording” tournaments with pairwise distinct vertices.
Find the expected number of Hamiltonian cycles in the chosen tournament.
Since the answer may be too large or lose precision, you only need to output the answer modulo .
That is: let the answer be . You must output an integer such that and . It can be proved that such an exists and is unique.
If no such tournament exists, output -1.
Input Format
One line with a positive integer .
Output Format
Output lines. On line , print the answer for input .
4
1
-1
1
1
Hint
Sample explanations:
- When , there is only one tournament, which is a single vertex.
- When , the tournament has only one edge and cannot form a Hamiltonian cycle.
- When , there are two “worth recording” tournaments, namely and , each having exactly Hamiltonian cycle, so the expected value is .
- When , there are many “worth recording” tournaments (too many to list here), but all that satisfy the condition are isomorphic, so the expected value is .
Constraints:
- In test points 1–3, .
- In test points 4–6, .
- In test points 7–10, .
- In test points 11–16, .
- In test points 17–25, .
The testdata has a gradient; each test point is worth 4 points.
To avoid constant-factor issues, the last two points have a 2 s time limit.
Terminology:
- Tournament: https://en.wikipedia.org/wiki/Tournament_(graph_theory)
- Hamiltonian cycle: https://en.wikipedia.org/wiki/Hamiltonian_cycle
by oscar
Translated by ChatGPT 5
京公网安备 11011102002149号