#FW0000104. Du lịch bằng ô tô (Travel by Car)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Du lịch bằng ô tô (Travel by Car)
Travel by Car
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are cities with undirected roads. The car starts with a full tank of capacity and consumes one fuel unit per distance unit. It may refill to full at any city. For each query , find the minimum number of refills at intermediate cities, or -1 if the journey is impossible. No refill at the destination is counted.
Input
First line: ; next lines contain undirected roads ; then integer followed by queries . Vertices are 1-indexed.
Output
Print one integer per query: minimum refills, 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 5
1 2 4
2 3 4
3
1 3
1 2
1 1
Output
1
0
0
Explanation
The trip 1 to 3 has two legs of length 4 and needs one refill at city 2. From 1 to 2 needs none, and staying at city 1 needs none.