#P3597. [POI 2015 R3] 旅行 Trips

[POI 2015 R3] 旅行 Trips

Description

Given a weighted directed graph with nn vertices and mm edges, where each edge weight is one of 11, 22, or 33.

Sort all possible paths by their total length and output the length of the kk-th shortest path. Note that a path does not have to be simple; the same vertex may be visited multiple times.

Input Format

The first line contains three integers n,m,kn, m, k (1n401 \le n \le 40, 1m10001 \le m \le 1000, 1k10181 \le k \le 10^{18}).

Each of the next mm lines contains three integers u,v,cu, v, c (1u,vn1 \le u, v \le n, uvu \ne v, 1c31 \le c \le 3), indicating there is a directed edge from uu to vv with length cc.

Parallel edges may exist.

Output Format

Output a single positive integer: the length of the kk-th shortest path. If it does not exist, output 1-1.

6 6 11
1 2 1
2 3 2
3 4 2
4 5 1
5 3 1
4 6 3
4

Hint

Sample explanation:

Paths of length 11: 121\to 2, 535\to 3, 454\to 5. Paths of length 22: 232\to 3, 343\to 4, 4534\to 5\to 3. Paths of length 33: 464\to 6, 1231\to 2\to 3, 3453\to 4\to 5, 5345\to 3\to 4. Paths of length 44: 53455\to 3\to 4\to 5.


Original title: Wycieczki.

Translated by ChatGPT 5