atcoder#ABC199F. [ABC199F] Graph Smoothing
[ABC199F] Graph Smoothing
Score : points
Problem Statement
We have a simple undirected graph with vertices and edges. The vertices are numbered through and the edges are numbered through . Edge connects Vertex and Vertex . Initially, Vertex has an integer written on it. You will do the following operation times:
- Choose one from the edges uniformly at random and independently from other choices. Let be the arithmetic mean of the numbers written on the two vertices connected by that edge. Replace each number written on those vertices with .
For each vertex , find the expected value of the number written on that vertex after operations, and print it modulo as described in Notes.
Notes
When printing a rational number, first, represent it as a fraction , where and are integers and is not divisible by (under the Constraints of this problem, such a representation is always possible). Then, print the only integer between and (inclusive) such that .
Constraints
- The given graph is simple.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the expected value of the number written on that vertex after operations, modulo , as described in Notes.
3 2 1
3 1 5
1 2
1 3
3
500000005
500000008
- If Edge is chosen in the only operation: the vertices written on Vertices will be , respectively.
- If Edge is chosen in the only operation: the vertices written on Vertices will be , respectively.
Thus, the expected values of the numbers written on Vertices are , respectively. If we express them modulo as described in Notes, they will be , respectively.
3 2 2
12 48 36
1 2
1 3
750000036
36
250000031
- If Edge is chosen in the -st operation:
The numbers written on Vertices will be , respectively. - If Edge is chosen in the -nd operation:
The numbers written on Vertices will be , respectively.
- If Edge is chosen in the -nd operation: The numbers written on Vertices will be , respectively.
- If Edge is chosen in the -st operation:
The numbers written on Vertices will be , respectively. - If Edge is chosen in the -nd operation:
The numbers written on Vertices will be , respectively.
- If Edge is chosen in the -nd operation: The numbers written on Vertices will be , respectively.
Each of these four scenarios happen with probability , so the expected values of the numbers written on Vertices are , respectively.
4 5 1000
578 173 489 910
1 2
2 3
3 4
4 1
1 3
201113830
45921509
67803140
685163678