#P10000. [集训队互测 2023] 矩阵快速幂
[集训队互测 2023] 矩阵快速幂
Background
Please note: this problem is not a matrix fast exponentiation template problem.
Problem Description
Given a weighted directed graph with vertices and edges, there may be multiple edges and self-loops. For each vertex, find the minimum path weight among all paths that start from vertex and traverse exactly edges, and output the result modulo . If such a path does not exist, output . 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 , denoting the subtask number.
The second line contains an integer , denoting the number of test cases.
For each test case:
- The first line contains three integers .
- The next lines each contain three integers , denoting a directed edge.
Output Format
For each test case, output one line containing 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 ( points): , .
- Subtask #2 ( points): , and for any , there exist and with equal weights.
- Subtask #3 ( points): , and for any , there exists with the same weight. Note that may equal . Depends on Subtask #2.
- Subtask #4 ( points): . Depends on Subtask #1.
- Subtask #5 ( points): . Depends on Subtask #1.
- Subtask #6 ( points): No special properties. Depends on Subtask #3, #4, #5.
For all testdata, , , , , , , . It is guaranteed that and .
The solution is in the attachment paper.pdf.
Translated by ChatGPT 5