#P8989. [北大集训 2021] 随机游走
[北大集训 2021] 随机游走
Background
CTT2021 D2T3.
Problem Description
Given a directed graph with vertices labeled . Initially, for all , there is a directed edge from to .
You may add more directed edges (any start and end vertices are allowed). Multiple edges and self-loops are allowed.
Player A starts from vertex and moves as a random walk until reaching vertex . You want to maximize the expected number of steps for Player A to move from to .
A random walk is defined as follows: suppose Player A is currently at vertex , and has outgoing edges. Then Player A chooses one of these outgoing edges uniformly at random and moves along it.
Input Format
The first line contains a positive integer , the number of test cases. It is guaranteed that .
The next lines each contain three integers , representing the number of vertices in the directed graph, the number of edges you add, and the modulus for the answer. It is guaranteed that , , , and is a prime.
Output Format
Output lines. The -th line contains an integer , meaning the maximum expected number of steps in the -th test case modulo .
(It can be proven that the answer is a rational number. Suppose its simplest form is . Then you need to output an such that . It is guaranteed that such an exists.)
4
3 2 97
10 25 233
6 12345 2333
1000000000 1000000000000000000 1000000007
6
131
1206
161905971
Hint
| Test Package ID | Special Property | Score | |||
|---|---|---|---|---|---|
| None | |||||
| None |
Translated by ChatGPT 5