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

#FW0000108. Cuộc phiêu lưu của Super Mario (Adventure of Super Mario)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

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 AA villages, numbered 11 to AA, and BB castles, numbered A+1A+1 to A+BA+B. Mario returns from castle A+BA+B to village 11. Walking along an undirected road of length ww costs ww time units. At most KK times, magic shoes allow instant travel between vertices when there is a route of length at most LL whose internal vertices are all villages. Find the minimum travel time.

Input

First line A,B,m,L,KA,B,m,L,K, then mm undirected roads u,v,wu,v,w.

Output

Print the minimum travel time, or -1 if no route exists.

Subtasks

  • Subtask 1 (40 points): 1≤A,B≤3,  0≤K≤2,  1≤L≤451\le A,B\le 3,\;0\le K\le 2,\;1\le L\le 45. 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.