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
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đườ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 vertices and positive weighted edges, find the minimum total weight of a walk from vertex to vertex using exactly edges. Vertices and edges may be revisited. Print -1 if no such walk exists. Exactly edges are required, not at most .
Input
First line ; then directed weighted edges . Vertices are -indexed; parallel edges are allowed.
Output
Print the minimum total weight or -1.
Subtasks
-
Subtask 1 (40 points): , , , . All input conditions remain in force.
-
Subtask 2 (60 points): , , , . 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.