Gates
InterviewTime limit2sMemory limit256 MB
Find the minimum travel time for each query pair of gates using walking and directed walkways.
- Level
Medium4 of 10
- Topics
- Shortest path, Graph
- Solved
- No attempts yet
Problem
An airport hallway has G gates. The entrance to gate i is 100·i metres from the start.
There are N moving walkways. Walkway i runs one way from gate Ai to gate Bi at speed Si metres per minute. At any point, at most one walkway moves in each direction.
You walk at speed W metres per minute. You may board a walkway only at its start and ride to its end. On walkway i your speed is W+Si.
Answer Q queries: the minimum time to travel from gate Xi to gate Yi.
Input
The first line has G, W, N, and Q. The next N lines contain Ai, Bi, and Si. The next Q lines contain Xi and Yi.
Output
Print Q lines, each with the minimum travel time in minutes. Answers within a relative error of 10^{-4} are accepted.