#abc199f. F - Graph Smoothing

F - Graph Smoothing

Score : 600600 points

问题描述

我们有一个简单的无向图,包含 NN 个顶点和 MM 条边。顶点编号为 11NN,边编号为 11MM

ii 条边连接顶点 XiX_i 和顶点 YiY_i。初始时,顶点 ii 上写有一个整数 AiA_i

接下来,你需要执行以下操作 KK 次:

  • 均匀随机地从 MM 条边中独立且随机地选择一条边。令 xx 为这条边所连接的两个顶点上所写数字的算术平均值。然后用 xx 替换这两个顶点上的每个数字。

对于每个顶点 ii,计算在经过 KK 次操作后该顶点上所写数字的期望值,并按照“注意事项”部分所述,将结果对 (109+7)(10^9 + 7) 取模后输出。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have a simple undirected graph with NN vertices and MM edges. The vertices are numbered 11 through NN and the edges are numbered 11 through MM.
Edge ii connects Vertex XiX_i and Vertex YiY_i. Initially, Vertex ii has an integer AiA_i written on it.
You will do the following operation KK times:

  • Choose one from the MM edges uniformly at random and independently from other choices. Let xx be the arithmetic mean of the numbers written on the two vertices connected by that edge. Replace each number written on those vertices with xx.

For each vertex ii, find the expected value of the number written on that vertex after KK operations, and print it modulo (109+7)(10^9 + 7) as described in Notes.

Notes

When printing a rational number, first, represent it as a fraction yx\frac{y}{x}, where xx and yy are integers and xx is not divisible by (109+7)(10^9+7) (under the Constraints of this problem, such a representation is always possible).
Then, print the only integer zz between 00 and (109+6)(10^9+6) (inclusive) such that xzy(mod109+7)xz \equiv y \pmod {10^9+7}.

Constraints

  • 2N1002 \le N \le 100
  • 1MN(N1)21 \le M \le \frac{N(N - 1)}{2}
  • 0K1090 \le K \le 10^9
  • 0Ai1090 \le A_i \le 10^9
  • 1XiN1 \le X_i \le N
  • 1YiN1 \le Y_i \le N
  • The given graph is simple.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM KK

A1A_1 A2A_2 A3A_3 \dots ANA_N

X1X_1 Y1Y_1

X2X_2 Y2Y_2

X3X_3 Y3Y_3

\hspace{15pt} \vdots

XMX_M YMY_M

Output

Print NN lines.
The ii-th line should contain the expected value of the number written on that vertex after KK operations, modulo (109+7)(10^9 + 7), 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 11 is chosen in the only operation: the vertices written on Vertices 1,2,31, 2, 3 will be 2,2,52, 2, 5, respectively.
  • If Edge 22 is chosen in the only operation: the vertices written on Vertices 1,2,31, 2, 3 will be 4,1,44, 1, 4, respectively.

Thus, the expected values of the numbers written on Vertices 1,2,31, 2, 3 are 3,32,923, \frac{3}{2}, \frac{9}{2}, respectively.
If we express them modulo (109+7)(10^9 + 7) as described in Notes, they will be 3,500000005,5000000083, 500000005, 500000008, respectively.

Sample Input 2

3 2 2
12 48 36
1 2
1 3

Sample Output 2

750000036
36
250000031
  • If Edge 11 is chosen in the 11-st operation: The numbers written on Vertices 1,2,31, 2, 3 will be 30,30,3630, 30, 36, respectively.
    • If Edge 11 is chosen in the 22-nd operation: The numbers written on Vertices 1,2,31, 2, 3 will be 30,30,3630, 30, 36, respectively.
    • If Edge 22 is chosen in the 22-nd operation: The numbers written on Vertices 1,2,31, 2, 3 will be 33,30,3333, 30, 33, respectively.
  • If Edge 22 is chosen in the 11-st operation: The numbers written on Vertices 1,2,31, 2, 3 will be 24,48,2424, 48, 24, respectively.
    • If Edge 11 is chosen in the 22-nd operation: The numbers written on Vertices 1,2,31, 2, 3 will be 36,36,2436, 36, 24, respectively.
    • If Edge 22 is chosen in the 22-nd operation: The numbers written on Vertices 1,2,31, 2, 3 will be 24,48,2424, 48, 24, respectively.

Each of these four scenarios happen with probability 14\frac{1}{4}, so the expected values of the numbers written on Vertices 1,2,31, 2, 3 are 1234,1444(=36),1174\frac{123}{4}, \frac{144}{4} (=36), \frac{117}{4}, 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