#FW0000107. Đặt phòng khách sạn (Hotel Booking)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đặt phòng khách sạn (Hotel Booking)
Hotel Booking
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Drive from city to city along bidirectional roads. You may drive at most 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 ; then hotel-city IDs; then roads with travel times in minutes, 1-indexed.
Output
Print the minimum hotel nights or -1.
Subtasks
-
Subtask 1 (40 points): . All input-format and graph conditions above apply.
-
Subtask 2 (60 points): . 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.