Canadian Computing Competition: 2014 Stage 2, Day 2, Problem 3
You're in an airport hallway with
gates, numbered from
to
in order. The entrance to gate
is
metres from the start of the hallway.
There are also
moving walkways. The
-th walkway runs from the entrance to gate
to the entrance to a different gate
at a speed of
metres per minute, in one direction only. At every point along the hallway, there is at most one walkway moving in each direction (towards the start of the hallway, or away from it). However, it is possible that one walkway starts at the same gate as another walkway, moving in the same direction, ends.
You can walk in either direction along the hallway at a speed of
metres per minute. Additionally, when at the start of a walkway, you may choose to get on it, in which case it'll carry you directly to its end - you may not get on or off in between these points. While on walkway
, you will move at a speed of
metres per minute.
To amuse yourself while waiting for your flight (which, of course, has been delayed), you've posed
queries to yourself. The
-th query involves finding the minimal time in which you can get from gate
to gate
. To make things more interesting, you've decided that you won't board your flight unless you can correctly answer all of these queries - so you'd better not screw up!
Input Specification
The first line contains four integers:
, the number of gates;
, the walking speed;
, the number of moving walkways; and
, the number of queries.
The next
lines each contain three integers dealing with walkway
:
, the starting gate;
, the ending gate;
, the speed. Note that
for any
.
The next
lines each contain two integers dealing with query
:
, the starting gate; and
, the ending gate.
You can assume that for some test cases, at least some of
,
, and
are small. This information may be helpful, or not.
Output Specification
The output is
lines, each line containing one real number which is the minimal amount of time required to travel from gate
to gate
(in minutes), for
. The output will be judged to be correct if the outputted answer is within a factor of
of the correct solution: that is, if
is the correct answer, values in the range
will be judged as correct.
Sample Input
Copy
6 10 3 4
2 3 15
4 2 150
3 6 290
3 2
2 3
1 4
4 6
Sample Output
Copy
10.0
4.0
24.0
6.25
Explanation of Output for Sample Input
For the first query, you should simply walk from gate
to gate
, covering
metres at a speed of
metres per minute.
For the second query, you should immediately get on the moving walkway going from gate
to gate
, covering
metres at a speed of
metres per minute.
For the third query, you should walk to gate
(taking
minutes), then take the walkway as before (taking
minutes), and then walk to gate
(taking
minutes).
Finally, for the fourth query, you should take the walkway from gate
to gate
(taking
minutes), then the walkway from gate
to gate
(taking
minutes), and finally the walkway from gate
to gate
(taking
minute).
Comments