atcoder#ABC199F. [ABC199F] Graph Smoothing

[ABC199F] Graph Smoothing

Score : 600600 points

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.

3 2 1
3 1 5
1 2
1 3
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.

3 2 2
12 48 36
1 2
1 3
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.

4 5 1000
578 173 489 910
1 2
2 3
3 4
4 1
1 3
201113830
45921509
67803140
685163678