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

#FW0000119. Đường đi đúng k cạnh II (Graph Paths II)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đường đi đúng k cạnh II (Graph Paths II)

Graph Paths II

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

Given a directed graph with nn vertices and mm positive weighted edges, find the minimum total weight of a walk from vertex 11 to vertex nn using exactly kk edges. Vertices and edges may be revisited. Print -1 if no such walk exists. Exactly kk edges are required, not at most kk.

Input

First line n,m,kn,m,k; then mm directed weighted edges u,v,wu,v,w. Vertices are 11-indexed; parallel edges are allowed.

Output

Print the minimum total weight or -1.

Subtasks

  • Subtask 1 (40 points): 2≤n≤52\le n\le 5, 1≤m≤201\le m\le 20, 1≤k≤121\le k\le 12, 1≤w≤201\le w\le 20. All input conditions remain in force.

  • Subtask 2 (60 points): 2≤n≤1002\le n\le 100, 1≤m≤n(n−1)1\le m\le n(n-1), 1≤k≤1091\le k\le 10^9, 1≤w≤1091\le w\le 10^9. All input conditions remain in force.

Examples

Input

3 4 8
1 2 5
2 3 4
3 1 1
3 2 2

Output

27

Explanation

The minimum-cost walk from 1 to 3 using exactly eight edges has total weight 27.