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

#FW0000107. Đặt phòng khách sạn (Hotel Booking)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đặt phòng khách sạn (Hotel Booking)

Hotel Booking

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Drive from city 11 to city nn along bidirectional roads. You may drive at most 600600 minutes per day. Overnight stays are only allowed in designated hotel cities. Find the minimum number of hotel nights, or -1 if travel is impossible.

Input

First line n,m,hn,m,h; then hh hotel-city IDs; then mm roads u,v,wu,v,w with travel times in minutes, 1-indexed.

Output

Print the minimum hotel nights or -1.

Subtasks

  • Subtask 1 (40 points): 3≤n≤6,  0≤h≤33\le n\le 6,\;0\le h\le 3. All input-format and graph conditions above apply.

  • Subtask 2 (60 points): 3≤n≤16,  0≤h≤83\le n\le 16,\;0\le h\le 8. All input-format and graph conditions above apply.

Examples

Input

3 2 1
2
1 2 450
2 3 450

Output

1

Explanation

The trip totals 900 minutes, exceeding the 600-minute daily limit. One night at hotel city 2 splits it into two 450-minute driving days, so the answer is 1.