#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 NN nodes and MM directed edges. Node ii (0≤i<N0 \le i < N) has a color label C[i]∈{0,1,⋯ ,K−1}C[i] \in \{0, 1, \cdots, K - 1\}. Edge jj (0≤j<M0 \le j < M) goes from node U[j]U[j] to node V[j]V[j] and has length D[j]D[j].

For the tourist Dundun, an ideal sightseeing route should satisfy the following conditions:

  • It is a simple path from node 00 to node N−1N - 1.
  • 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 LL.

More specifically, an ideal sightseeing route is a sequence of nodes, such as (t0,t1,⋯ ,tq−1)(t_0, t_1, \cdots, t_{q-1}), that satisfies all of the following:

  • For each ii (0≤i<q−10 \le i < q - 1), there exists a directed edge from node tit_i to node ti+1t_{i+1}.
  • t0=0t_0 = 0 and tq−1=N−1t_{q-1} = N - 1.
  • For every pair i,ji, j (0≤i<j<q0 \le i < j < q), we have C[ti]≠C[tj]C[t_i] \ne C[t_j].
  • q≤Lq \le L.

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 N,M,LN, M, L and KK, 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 NN integers C[0],C[1],⋯ ,C[N−1]C[0], C[1], \cdots, C[N - 1], representing the color label of each node.

Next comes the edge information.

The third line contains MM integers U[0],U[1],⋯ ,U[M−1]U[0], U[1], \cdots, U[M - 1], representing the starting node of each directed edge.

The fourth line contains MM integers V[0],V[1],⋯ ,V[M−1]V[0], V[1], \cdots, V[M - 1], representing the ending node of each directed edge.

The fifth line contains MM integers D[0],D[1],⋯ ,D[M−1]D[0], D[1], \cdots, D[M - 1], representing the length of each directed edge.

The input guarantees that there is no edge whose start and end are the same, such as (u,u)(u, u). Each directed edge (u,v)(u, v) appears at most once, but it is possible that both (u,v)(u, v) and (v,u)(v, u) 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 00 to node 55. The longest one is (0,1,5)(0, 1, 5), with length 99.

Colored Path Number of Nodes Length
(0,1,3,5)(0, 1, 3, 5) 44 77
(0,1,4,5)(0, 1, 4, 5) ^ 44
(0,2,4,5)(0, 2, 4, 5) 88
(0,1,5)(0, 1, 5) 33 99
(0,4,5)(0, 4, 5) ^ 55

Subtasks

20%20\% of the testdata satisfies: for every ii (0≤i<N−10 \le i < N - 1), C[i]≤C[i+1]C[i] \le C[i + 1], and for every jj (0≤j<M0 \le j < M), U[j]<V[j]U[j] < V[j].

Another 30%30\% of the testdata satisfies: K≤15K \le 15.

All testdata satisfies:

  • 2≤N≤1002 \le N \le 100
  • 1≤M≤50001 \le M \le 5000
  • 2≤L≤9≤K≤302 \le L \le 9 \le K \le 30
  • C[0]=0C[0] = 0 and C[N−1]=K−1C[N - 1] = K - 1
  • For each ii (1≤i≤N−21 \le i \le N - 2):
$$\begin{aligned} &1 \le C[i] \le K - 2 \end{aligned}$$
  • For each jj (0≤j<M0 \le j < M):
$$\begin{aligned} &0 \le U[j], V[j] < N \\ &C[U[j]] \ne C[V[j]] \\ &1 \le D[j] \le 10^6 \end{aligned}$$
  • There is at least one colored path from node 00 to node N−1N - 1 with no more than LL nodes.

Translated by ChatGPT 5