#abc277g. G - Random Walk to Millionaire
G - Random Walk to Millionaire
Score : points
问题描述
你得到一个包含 个顶点和 条边的连通简单无向图。
对于 ,第 条边连接顶点 和顶点 。
高桥从顶点 的 等级 开始,并将执行以下动作恰好 次。
- 首先,他随机均匀地选择当前所在顶点的一个相邻顶点,并移动到所选顶点。
- 然后,根据他移动到的顶点 发生以下情况:
- 若 :高桥的等级增加 。
- 若 :高桥获得 日元,其中 是他当前的等级。
请计算在上述 次动作中,高桥收到的总金额的期望值,结果对 (参见注释)取模。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a connected simple undirected graph consisting of vertices and edges.
For , the -th edge connects vertex and vertex .
Takahashi starts at Level on vertex , and will perform the following action exactly times.
- First, choose one of the vertices adjacent to the vertex he is currently on, uniformly at random, and move to the chosen vertex.
- Then, the following happens according to the vertex he has moved to.
- If : Takahashi's Level increases by .
- If : Takahashi receives a money of yen, where is his current Level.
Print the expected value of the total amount of money Takahashi receives during the actions above, modulo (see Notes).
Notes
It can be proved that the sought expected value is always a rational number. Additionally, under the Constraints of this problem, when that value is represented as using two coprime integers and , it can also be proved that there is a unique integer such that and . Find this .
Constraints
- $i \neq j \implies \lbrace u_i, v_i\rbrace \neq \lbrace u_j, v_j \rbrace$
- The given graph is connected.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
5 4 8
4 5
2 3
2 4
1 2
0 0 1 1 0
Sample Output 1
89349064
Among the multiple paths that Takahashi may traverse, let us take a case where Takahashi starts on vertex and goes along the path $1 \rightarrow 2 \rightarrow 4 \rightarrow 5 \rightarrow 4 \rightarrow 2 \rightarrow 1 \rightarrow 2 \rightarrow 3$, and compute the total amount of money he receives.
- In the first action, he moves from vertex to an adjacent vertex, vertex . Then, since , his Level increases to .
- In the second action, he moves from vertex to an adjacent vertex, vertex . Then, since , he receives yen.
- In the third action, he moves from vertex to an adjacent vertex, vertex . Then, since , his Level increases to .
- In the fourth action, he moves from vertex to an adjacent vertex, vertex . Then, since , he receives yen.
- In the fifth action, he moves from vertex to an adjacent vertex, vertex . Then, since , his Level increases to .
- In the sixth action, he moves from vertex to an adjacent vertex, vertex . Then, since , his Level increases to .
- In the seventh action, he moves from vertex to an adjacent vertex, vertex . Then, since , his Level increases to .
- In the eighth action, he moves from vertex to an adjacent vertex, vertex . Then, since , he receives yen.
Thus, he receives a total of yen.
Sample Input 2
8 12 20
7 6
2 6
6 4
2 1
8 5
7 2
7 5
3 7
3 5
1 8
6 3
1 4
0 0 1 1 0 0 0 0
Sample Output 2
139119094
update @ 2024/3/10 11:41:01