atcoder#ABC277G. [ABC277G] Random Walk to Millionaire
[ABC277G] Random Walk to Millionaire
Score : points
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.
- 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.
5 4 8
4 5
2 3
2 4
1 2
0 0 1 1 0
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.
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
139119094