PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000433. Đường đi có cạnh lớn nhất nhỏ nhất (Minimum maximum on the Path)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đường đi có cạnh lớn nhất nhỏ nhất (Minimum maximum on the Path)

Minimum maximum on the Path

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A road network consists of nn intersections numbered from 11 to nn and mm one-way roads. Each road goes from an intersection with a smaller number to one with a larger number and has a nonnegative integer weight.

You must travel from intersection 11 to intersection nn using at most dd roads. The value of a path is the largest weight among the roads it uses.

Find a valid path of minimum value. If several paths have the same minimum value, output any of them. If intersection nn cannot be reached within the road limit, output -1.

Input

The first line contains three integers n,m,dn,m,d: the number of intersections, the number of roads, and the maximum number of roads allowed on the path.

Each of the next mm lines contains three integers ui,vi,wiu_i,v_i,w_i, describing a one-way road from intersection uiu_i to intersection viv_i with weight wiw_i.

Output

If no valid path exists, output only -1.

Otherwise, print an integer kk, the number of roads used, on the first line. On the second line, print k+1k+1 integers representing the intersections in traversal order, beginning with 11 and ending with nn. The path must satisfy k≤dk\le d and have the minimum possible value.

Subtasks

  • Subtask 1 (20 points): 2≤n≤122\le n\le 12, 1≤m≤661\le m\le 66, 1≤d≤n−11\le d\le n-1, 1≤ui<vi≤n1\le u_i<v_i\le n, 0≤wi≤1090\le w_i\le 10^9 for every 1≤i≤m1\le i\le m; no two roads have the same ordered pair of endpoints.

  • Subtask 2 (30 points): 2≤n≤10002\le n\le 1000, 1≤m≤40001\le m\le 4000, 1≤d≤n−11\le d\le n-1, 1≤ui<vi≤n1\le u_i<v_i\le n, 0≤wi≤1090\le w_i\le 10^9 for every 1≤i≤m1\le i\le m; no two roads have the same ordered pair of endpoints.

  • Subtask 3 (50 points): 2≤n≤1052\le n\le 10^5, 1≤m≤1051\le m\le 10^5, 1≤d≤n−11\le d\le n-1, 1≤ui<vi≤n1\le u_i<v_i\le n, 0≤wi≤1090\le w_i\le 10^9 for every 1≤i≤m1\le i\le m; no two roads have the same ordered pair of endpoints.

Examples

Input

4 5 2
1 2 5
2 3 3
1 3 7
2 4 6
3 4 4

Output

2
1 2 4

Explanation

There are two paths using at most two roads: 1→2→41\to2\to4 has value max⁡(5,6)=6\max(5,6)=6, while 1→3→41\to3\to4 has value max⁡(7,4)=7\max(7,4)=7. The path 1→2→3→41\to2\to3\to4 has value 55 but uses three roads, exceeding d=2d=2. Thus the minimum feasible value is 66, attained by the two-road path through intersection 22.