atcoder#ABC213H. [ABC213H] Stroll

[ABC213H] Stroll

Score : 600600 points

Problem Statement

Takahashi has decided to wander around his house. During his walk, he will roam between NN points called Point 11, Point 22, \dots, Point NN, where Point 11 is his house. There are MM pairs of points connected by roads; let (ai,bi)(a_i, b_i) be the ii-th of these pairs. There are pi,dp_{i, d} roads with a length of dd (1dT)(1 \leq d \leq T) kilometers connecting Point aia_i and Point bib_i.

Takahashi wants to know the number of TT kilometers courses that begin and end at his house. Here, a TT kilometers course is defined as follows.

  • An alternating sequence with points and roads v0=1,e0,v1,,ek1,vk=1v_0 = 1, e_0, v_1, \dots,e_{k-1}, v_k = 1 such that eie_i (0ik1)(0 \leq i \leq k-1) connects viv_i and vi+1v_{i+1}, and the total length of eie_i is TT kilometers.

Help Takahashi by finding the number of such courses modulo 998244353998244353. Two courses are considered different when they are different as sequences.

Constraints

  • 2N102 \leq N \leq 10
  • $1 \leq M \leq \min \left(10, \frac{N(N-1)}{2} \right)$
  • 1T4×1041 \leq T \leq 4 \times 10^4
  • 1ai<biN1 \leq a_i \lt b_i \leq N
  • (ai,bi)(aj,bj)(a_i, b_i) \neq (a_j, b_j) if iji \neq j.
  • 0pi,j<9982443530 \leq p_{i,j} \lt 998244353

Input

Input is given from Standard Input in the following format:

NN MM TT

a1a_1 b1b_1

p1,1p_{1,1} p1,2p_{1,2} \ldots p1,Tp_{1,T}

\vdots

aMa_M bMb_M

pM,1p_{M,1} pM,2p_{M,2} \ldots pM,Tp_{M,T}

Output

Print the number of desirable courses, modulo 998244353998244353.

3 2 2
1 2
1 0
1 3
2 0
5

Around his house, there are:

  • one 11-kilometer road connecting Point 11 and Point 22, and
  • two 11-kilometer roads connecting Point 11 and Point 33.

We have the following five desirable courses:

  • 1×1=11 \times 1 = 1 course that goes Point 11 \to Point 22 \to Point 11, and
  • 2×2=42 \times 2 = 4 courses that goes Point 11 \to Point 33 \to Point 11.
3 3 4
1 2
3 0 0 0
1 3
0 1 0 0
2 3
2 0 0 0
130

Around his house, there are:

  • three 11-kilometer roads connecting Point 11 and Point 22,
  • one 22-kilometer road connecting Point 11 and Point 33, and
  • two 11-kilometer roads connecting Point 22 and Point 33.

The desirable courses can be classified into the following categories, according to the points visited:

  • Point 11 \to Point 22 \to Point 11 \to Point 22 \to Point 11,
  • Point 11 \to Point 22 \to Point 33 \to Point 11,
  • Point 11 \to Point 22 \to Point 33 \to Point 22 \to Point 11,
  • Point 11 \to Point 33 \to Point 11, and
  • Point 11 \to Point 33 \to Point 22 \to Point 11.

We have 8181, 66, 3636, 11, and 66 course(s) of these categories, respectively.

2 1 5
1 2
31415 92653 58979 32384 62643
844557977