atcoder#ABC277G. [ABC277G] Random Walk to Millionaire

[ABC277G] Random Walk to Millionaire

Score : 600600 points

Problem Statement

You are given a connected simple undirected graph consisting of NN vertices and MM edges. For i=1,2,,Mi = 1, 2, \ldots, M, the ii-th edge connects vertex uiu_i and vertex viv_i.

Takahashi starts at Level 00 on vertex 11, and will perform the following action exactly KK 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 vv he has moved to.- If Cv=0C_v = 0: Takahashi's Level increases by 11.
    • If Cv=1C_v = 1: Takahashi receives a money of X2X^2 yen, where XX is his current Level.
  • If Cv=0C_v = 0: Takahashi's Level increases by 11.
  • If Cv=1C_v = 1: Takahashi receives a money of X2X^2 yen, where XX is his current Level.

Print the expected value of the total amount of money Takahashi receives during the KK actions above, modulo 998244353998244353 (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 PQ\frac{P}{Q} using two coprime integers PP and QQ, it can also be proved that there is a unique integer RR such that R×QP(mod998244353)R \times Q \equiv P\pmod{998244353} and 0R<9982443530 \leq R \lt 998244353. Find this RR.

Constraints

  • 2N30002 \leq N \leq 3000
  • N1Mmin{N(N1)/2,3000}N-1 \leq M \leq \min\lbrace N(N-1)/2, 3000\rbrace
  • 1K30001 \leq K \leq 3000
  • 1ui,viN1 \leq u_i, v_i \leq N
  • uiviu_i \neq v_i
  • $i \neq j \implies \lbrace u_i, v_i\rbrace \neq \lbrace u_j, v_j \rbrace$
  • The given graph is connected.
  • Ci{0,1}C_i \in \lbrace 0, 1\rbrace
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN MM KK

u1u_1 v1v_1

u2u_2 v2v_2

\vdots

uMu_M vMv_M

C1C_1 C2C_2 \ldots CNC_N

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 11 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.

  1. In the first action, he moves from vertex 11 to an adjacent vertex, vertex 22. Then, since C2=0C_2 = 0, his Level increases to 11.
  2. In the second action, he moves from vertex 22 to an adjacent vertex, vertex 44. Then, since C4=1C_4 = 1, he receives 12=11^2 = 1 yen.
  3. In the third action, he moves from vertex 44 to an adjacent vertex, vertex 55. Then, since C5=0C_5 = 0, his Level increases to 22.
  4. In the fourth action, he moves from vertex 55 to an adjacent vertex, vertex 44. Then, since C4=1C_4 = 1, he receives 22=42^2 = 4 yen.
  5. In the fifth action, he moves from vertex 44 to an adjacent vertex, vertex 22. Then, since C2=0C_2 = 0, his Level increases to 33.
  6. In the sixth action, he moves from vertex 22 to an adjacent vertex, vertex 11. Then, since C1=0C_1 = 0, his Level increases to 44.
  7. In the seventh action, he moves from vertex 11 to an adjacent vertex, vertex 22. Then, since C2=0C_2 = 0, his Level increases to 55.
  8. In the eighth action, he moves from vertex 22 to an adjacent vertex, vertex 33. Then, since C3=1C_3 = 1, he receives 52=255^2 = 25 yen.

Thus, he receives a total of 1+4+25=301 + 4 + 25 = 30 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