#d1206. Damaged Bicycle
Damaged Bicycle
Damaged Bicycle
Problem Source
CCPC Harbin 2021 G
Problem Description
The campus can be viewed as a graph with vertices and bidirectional edges, where the -th edge has length . Your dormitory is at vertex and the teaching building is at vertex ; you want to go from the dormitory to the teaching building. Your walking speed is units per second, and your cycling speed is units per second.
According to the shared-bike app, there are bike-parking spots on campus. The -th spot is at vertex , but with probability the bike there may be broken. However, you only find out whether the -th bike is good after arriving at vertex and scanning the QR code. If the bike is good, you can ride it to the destination.
Under the optimal strategy, what is the minimum expected time for you to reach the destination? If vertex cannot be reached, output -1.
Input Format
The first line contains two integers (), the walking and cycling speeds.
The next line contains two integers (), the number of vertices and edges.
The next lines each contain three integers (, , ), indicating a bidirectional edge of length between and .
The next line contains an integer (), the number of bikes.
The next lines each contain two integers (, ), the location of the bike and the probability that it is broken.
It is guaranteed that all bike locations are distinct.
Output Format
If the destination cannot be reached, output -1; otherwise output the minimum expected time. An absolute or relative error not exceeding is acceptable.
Sample Input 1
3 15
4 3
1 2 600
1 3 300
2 4 900
1
3 50
Sample Output 1
460.000000
Sample Input 2
3 15
5 4
1 2 600
1 3 300
2 5 900
3 4 3
2
3 50
4 0
Sample Output 2
220.600000
Sample Input 3
3 15
5 4
1 2 600
1 3 300
4 5 900
3 2 300
2
3 50
4 0
Sample Output 3
-1
Sample Explanation
For the first sample, one possible strategy is:
- Follow the route to try the only bike on campus.
- If the bike is broken, walk along the route , or ride a bike.
Considering the travel-time cost:
If the bike is broken, you walk along $1 \rightarrow 3 \rightarrow 1 \rightarrow 2 \rightarrow 4$, total length . So the time cost is .
If the bike is not broken, you walk along , total length , then ride the bike along , total length . So the time cost is .
The bike is broken with probability . So the expected time cost is $\frac{50}{100} \times 700 + (1 - \frac{50}{100}) \times 220 = 460$.