#abc199f. F - Graph Smoothing
F - Graph Smoothing
Score : points
问题描述
我们有一个简单的无向图,包含 个顶点和 条边。顶点编号为 到 ,边编号为 到 。
第 条边连接顶点 和顶点 。初始时,顶点 上写有一个整数 。
接下来,你需要执行以下操作 次:
- 均匀随机地从 条边中独立且随机地选择一条边。令 为这条边所连接的两个顶点上所写数字的算术平均值。然后用 替换这两个顶点上的每个数字。
对于每个顶点 ,计算在经过 次操作后该顶点上所写数字的期望值,并按照“注意事项”部分所述,将结果对 取模后输出。
以上为通义千问 qwen-max 翻译,仅供参考。
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.
Sample Input 1
3 2 1
3 1 5
1 2
1 3
Sample Output 1
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.
Sample Input 2
3 2 2
12 48 36
1 2
1 3
Sample Output 2
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.
Sample Input 3
4 5 1000
578 173 489 910
1 2
2 3
3 4
4 1
1 3
Sample Output 3
201113830
45921509
67803140
685163678
相关
在下列比赛中: