#P10000. [集训队互测 2023] 矩阵快速幂

[集训队互测 2023] 矩阵快速幂

Background

Please note: this problem is not a matrix fast exponentiation template problem.

Problem Description

Given a weighted directed graph with nn vertices and mm edges, there may be multiple edges and self-loops. For each vertex, find the minimum path weight among all paths that start from vertex 11 and traverse exactly kk edges, and output the result modulo 998244353998244353. If such a path does not exist, output 1-1. There are multiple test cases.

The path weight is defined as the sum of the weights of all edges on the path.

Input Format

The first line contains an integer SS, denoting the subtask number.

The second line contains an integer TT, denoting the number of test cases.

For each test case:

  • The first line contains three integers n,m,kn, m, k.
  • The next mm lines each contain three integers u,v,wu, v, w, denoting a directed edge.

Output Format

For each test case, output one line containing nn integers separated by spaces, representing the answers.

1
1
5 5 101
1 2 1
2 3 100
3 4 10000
4 2 1000000
2 5 10

-1 -1 33333401 -1 33333311

见下发文件 ex_matrix1.in
见下发文件 ex_matrix1.ans
见下发文件 ex_matrix2.in
见下发文件 ex_matrix2.ans

Hint

  • Subtask #1 (1010 points): n3106\sum n ^ 3\leq 10 ^ 6, k1018k\leq 10 ^ {18}.
  • Subtask #2 (1515 points): m=2n2m = 2n - 2, and for any 1i<n1\leq i < n, there exist (i,i+1)(i, i + 1) and (i+1,i)(i + 1, i) with equal weights.
  • Subtask #3 (2020 points): m2n2m\geq 2n - 2, and for any (u,v)(u, v), there exists (v,u)(v, u) with the same weight. Note that uu may equal vv. Depends on Subtask #2.
  • Subtask #4 (1515 points): n3106\sum n ^ 3\leq 10 ^ 6. Depends on Subtask #1.
  • Subtask #5 (1515 points): k1018k\leq 10 ^ {18}. Depends on Subtask #1.
  • Subtask #6 (2525 points): No special properties. Depends on Subtask #3, #4, #5.

For all testdata, 1S61\leq S\leq 6, 1T1041\leq T\leq 10 ^ 4, 2n3002\leq n\leq 300, 1m2n1\leq m\leq 2n, 1k10641\leq k\leq 10 ^ {64}, 1u,vn1\leq u, v\leq n, 1w10181\leq w\leq 10 ^ {18}. It is guaranteed that n2×105\sum n \leq 2\times 10 ^ 5 and n32.7×107\sum n ^ 3 \leq 2.7 \times 10 ^ 7.

The solution is in the attachment paper.pdf.

Translated by ChatGPT 5