#P10326. 自由(Freedom)

    ID: 11581 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>数学洛谷原创提交答案枚举组合数学生成函数线性代数洛谷比赛

自由(Freedom)

Background

Completely abstract, the infinite “freedom” that is only allowed in mathematics.


“Light of freedom”, the knight of the unknown — Zhi Xiu. Even when facing infinite despair, he can turn it into infinite freedom.

Problem Description

Given a directed graph with nn nodes and mm edges, both nodes and edges have weights. It is guaranteed that for any two nodes u,vu, v, there is at most one edge from uu to vv.

A path PP is a node sequence u1,,uku_1,\cdots,u_k, where for any 1i<k1\leq i < k, there is an edge from uiu_i to ui+1u_{i+1} (denote this edge as eie_i). Define the edge weight of PP as the product of the weights of all eie_i, its node weight as the sum of the weights of all uiu_i, and its length as kk. In particular, if k=1k=1, define its edge weight to be 11.

For two paths P1,P2P_1, P_2 with lengths L1,L2L_1, L_2, and node sequences u1,,uL1u_1,\cdots,u_{L_1} and v1,,vL2v_1,\cdots,v_{L_2} respectively, they are defined to be the same if and only if L1=L2L_1=L_2 and ui=viu_i=v_i holds for all 1iL11\le i \le L_1.

Given a positive integer VV, compute the sum of the edge weights of all distinct paths whose node weight is VV. The answer may be very large; output it modulo 998244353998244353.

Input testdata download link: Link1, extraction code: 92ih;
Backup download link and instructions: Link2.

Input Format

The first line contains a positive integer TT, indicating the test point ID.

The second line contains three positive integers n,m,Vn, m, V, with meanings as described above.
The third line contains nn positive integers a1,,ana_1,\cdots,a_n, where aia_i is the weight of node ii.
The next mm lines each contain three positive integers ui,vi,wiu_i, v_i, w_i, indicating that there is an edge from node uiu_i to node viv_i with weight wiw_i.

Output Format

Output one line with one integer, representing the answer.

0
3 5 12
2 4 6
2 3 5
1 2 3
3 1 7
3 2 11
1 1 2
155

Hint

[Sample 11 Explanation]

In the sample, V=12V=12. The paths whose node weight is 1212 are:
(What is given are the node IDs on the path; in the sample, each node’s weight happens to be twice its ID.)

  • 1111111 \to 1\to 1\to 1\to 1\to 1, edge weight is 25=322^5=32.
  • 111121\to 1\to 1\to 1 \to 2, edge weight is 3×23=243\times 2^3=24.
  • 1231\to 2 \to 3, edge weight is 3×5=153\times 5=15.
  • 2312\to 3\to 1, edge weight is 5×7=355\times 7=35.
  • 31113\to 1\to 1\to 1, edge weight is 7×22=287\times 2^2=28.
  • 3123\to 1\to 2, edge weight is 7×3=217\times 3=21.

So the answer is 32+24+15+35+28+21=15532+24+15+35+28+21=155.

[Data Information]

Test Point ID 1 2 3 4 5 6 7 8 9 10
Test Point Name W K_1 K_2 K_3 MP_1 MP_2 MP_3 MP_4 R Finale
Score 1010

For all testdata, 1n1051\le n \le10^5, 1mmin(n2,106)1\le m \le \min(n^2,10^6), 1V10100000001\le V \le 10^{10000000}.

[Reminder]
Time is precious. Running code takes time, and your thinking also takes time. Fortunately, these two things can happen at the same time. Hopefully, within this limited time, you can do more and achieve a better score.

Translated by ChatGPT 5