#P5418. [CTSC2016] NOIP十合一(数据疑似有误)
[CTSC2016] NOIP十合一(数据疑似有误)
Background
This is an output-only problem.
Problem Description
At the contest site of NOIP2044, Little D encountered the following problem:
You are given a graph with vertices, directed edges with weights, and queries. Each query asks: how many paths are there from vertex to vertex with total length ? You only need to output the answer modulo .
Little D thought for a long time but still could not solve it. After leaving in disappointment, he obtained the testdata for this problem from the official website. There are test cases in total. Little D really wants to solve this problem, so he asks for your help and gives you the input of these test cases. You, being smart, can surely help Little D compute the output for each test case.
Input Format
The input files noip1.in~noip10.in are already included in the download package.
The first line of each input file contains positive integers , representing the number of vertices, the number of edges, the number of queries, and the modulus. The vertices are numbered as integers from to .
The next lines describe the weighted directed edges. In the -th line there are integers , meaning the -th edge starts at , ends at , and has weight .
The next lines describe the queries. In the -th line there are integers , meaning the -th query asks for the number of paths from vertex to vertex with total length , modulo .
Output Format
The output files are noip1.out~noip10.out, corresponding to the respective input files.
Each output file contains at most lines. Each line contains a non-negative integer less than , representing the answers to the first queries of that test case.
3 4 2 10
1 1 2
1 2 2
1 3 1
2 3 3
1 3 5
1 3 3
2
1
Hint
Explanation for Sample 1:
For the first query, there are exactly two paths from vertex to vertex with length . Assume the edges are numbered from to . Then the edges passed by these two paths are:
Path :
Path : .
About the other samples
The download package provides sampleout for each test case, which corresponds to the correct output for the first query of each test case.
Input data download
Scoring
There is no special judge. The judging follows the traditional problem scoring method. You get points for a test case only if your output is exactly the same as the standard output.
Notes
This problem may use the following knowledge:
Characteristic polynomial: For an matrix , define an -th degree polynomial in as , where is the identity matrix and is the determinant. We call the characteristic polynomial of .
Cayley-Hamilton theorem: For the characteristic polynomial of a square matrix , we always have . That is, if we substitute the matrix itself into the characteristic polynomial, the result is the zero matrix.
Translated by ChatGPT 5