#FW0000108. Cuộc phiêu lưu của Super Mario (Adventure of Super Mario)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Cuộc phiêu lưu của Super Mario (Adventure of Super Mario)
Adventure of Super Mario
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
There are villages, numbered to , and castles, numbered to . Mario returns from castle to village . Walking along an undirected road of length costs time units. At most times, magic shoes allow instant travel between vertices when there is a route of length at most whose internal vertices are all villages. Find the minimum travel time.
Input
First line , then undirected roads .
Output
Print the minimum travel time, or -1 if no route exists.
Subtasks
-
Subtask 1 (40 points): . All input-format and graph conditions above apply.
-
Subtask 2 (60 points): $1\le A\le 8,\;1\le B\le 7,\;0\le K\le 5,\;1\le L\le 100$. All input-format and graph conditions above apply.
Examples
Input
2 1 2 15 1
1 2 10
2 3 10
Output
10
Explanation
Starting at castle 3, Mario uses one instant boot jump to village 2 over distance 10, then walks 10 minutes from 2 to 1. A direct instant jump over distance 20 exceeds limit 15, so the answer is 10.