#P7702. [CCC 2014] 登机口

[CCC 2014] 登机口

Description

You are now in an airport with GG boarding gates, numbered from 11 to GG. Gate ii is 100i100i meters away from the airport entrance.

There are also NN horizontal moving walkways in the airport. The ii-th walkway moves one-way from gate AiA_i to another gate BiB_i at SiS_i meters per minute. At any point in the corridor, in the same direction (toward the airport entrance or away from the airport entrance), there is at most one moving walkway in motion. However, it is possible that two moving walkways start from the same gate and have the same direction and the same destination.

You can walk along the corridor at speed WW meters per minute. When you are at the start of a moving walkway, you may choose to step onto it. If you do, it will take you to its endpoint. Even if a walkway passes through some position that is not its start or end, you cannot get on or off at that position. While you are on moving walkway ii, your speed is W+SiW+S_i meters per minute.

While waiting for your delayed flight, for fun you ask yourself QQ questions. The ii-th question asks for the shortest time to get from gate XX to gate YY. To make it more interesting, you decide that if you answer any question incorrectly, you will not board the plane, so you had better not mess it up.

Input Format

The first line contains four integers G,W,N,QG, W, N, Q, representing the number of gates, walking speed, the number of horizontal moving walkways, and the number of queries.

The next NN lines each contain three integers Ai,Bi,SiA_i, B_i, S_i, representing the start gate, end gate, and speed of moving walkway ii. Here AiBiA_i\ne B_i.

The next QQ lines each contain two integers X,YX, Y, representing the start gate and the destination gate.

Output Format

Output QQ lines. Each line contains one real number, the minimum number of minutes needed to go from gate XX to gate YY.

Your answer will be judged as follows: if DD is the standard answer, then any result in the range [D×(1104),D×(1+104)][D\times (1-10^{-4}), D\times (1+10^{-4})] is considered correct.

6 10 3 4
2 3 15
4 2 150
3 6 290
3 2
2 3
1 4
4 6
10.0
4.0
24.0
6.25

Hint

For the first query, you only need to walk from gate 33 to gate 22. The distance between the two gates is 100100 meters, and your speed is 1010 meters per minute.

For the second query, you should take the moving walkway from gate 22 to gate 33. The distance is 100100 meters, and your speed is 2525 meters per minute.

For the third query, you should spend 1010 minutes walking to gate 22, then spend 44 minutes taking the moving walkway described in query 22, and then spend 1010 minutes walking to gate 44.

For the fourth query, you should spend 1.251.25 minutes taking the moving walkway from gate 44 to gate 22, then spend 44 minutes taking the moving walkway from gate ?? to gate 22, and finally spend 33 minutes taking the plane from gate 11 to gate 66.

For some testdata, at least one of G,N,QG, N, Q is small. This information may be useful, or it may not be.

For 100%100\% of the testdata, 1Ai,Bi,X,YG1091\le A_i, B_i, X, Y\le G\le 10^9, 1N,Q1051\le N, Q\le 10^5.

Translated by ChatGPT 5