#P16068. [CSPro 32] 彩色路径
[CSPro 32] 彩色路径
Background
Luogu’s testdata is only for non-official sharing and communication, and is not the official testdata. Official judging link: https://www.cspro.org/.
Problem Description
The road map of Xixi Aifu Island can be viewed as a graph with nodes and directed edges. Node () has a color label . Edge () goes from node to node and has length .
For the tourist Dundun, an ideal sightseeing route should satisfy the following conditions:
- It is a simple path from node to node .
- It is a colored path, meaning that all nodes on the path have pairwise distinct color labels.
- The number of nodes on the path is less than or equal to .
More specifically, an ideal sightseeing route is a sequence of nodes, such as , that satisfies all of the following:
- For each (), there exists a directed edge from node to node .
- and .
- For every pair (), we have .
- .
The length of a path is defined as the sum of the lengths of its edges. Your task is to find the longest sightseeing route that satisfies all of Dundun’s requirements.
Input Format
Read input from standard input.
The input has five lines.
The first line contains four positive integers and , representing the number of nodes, the number of edges, the upper limit on the number of nodes in an ideal sightseeing route, and the range of color labels.
The second line contains integers , representing the color label of each node.
Next comes the edge information.
The third line contains integers , representing the starting node of each directed edge.
The fourth line contains integers , representing the ending node of each directed edge.
The fifth line contains integers , representing the length of each directed edge.
The input guarantees that there is no edge whose start and end are the same, such as . Each directed edge appears at most once, but it is possible that both and exist at the same time.
Output Format
Write to standard output.
Output one number, representing the maximum length of an ideal sightseeing route.
6 9 4 10
0 2 2 3 3 9
0 0 0 1 1 1 2 3 4
1 2 4 3 4 5 4 5 5
1 2 4 3 2 8 5 3 1
9
Hint
Sample Explanation
Below is the sample graph, where the black and red numbers represent node indices and edge lengths, respectively.
:::align{center}
:::
As shown in the table below, under the restriction of using no more than four nodes, there are five colored paths from node to node . The longest one is , with length .
| Colored Path | Number of Nodes | Length |
|---|---|---|
| ^ | ||
| ^ |
Subtasks
of the testdata satisfies: for every (), , and for every (), .
Another of the testdata satisfies: .
All testdata satisfies:
- and
- For each ():
- For each ():
- There is at least one colored path from node to node with no more than nodes.
Translated by ChatGPT 5