#d1206. Damaged Bicycle

Damaged Bicycle

Damaged Bicycle

Problem Source

CCPC Harbin 2021 G

Problem Description

The campus can be viewed as a graph with nn vertices and mm bidirectional edges, where the ii-th edge has length wiw_i. Your dormitory is at vertex 11 and the teaching building is at vertex nn; you want to go from the dormitory to the teaching building. Your walking speed is tt units per second, and your cycling speed is rr units per second.

According to the shared-bike app, there are kk bike-parking spots on campus. The ii-th spot is at vertex aia_i, but with probability pi100\frac{p_i}{100} the bike there may be broken. However, you only find out whether the ii-th bike is good after arriving at vertex aia_i 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 nn cannot be reached, output -1.

Input Format

The first line contains two integers t,rt, r (1≤t≤r≤1041 \le t \le r \le 10^4), the walking and cycling speeds.

The next line contains two integers n,mn, m (1≤n,m≤1051 \le n, m \le 10^5), the number of vertices and edges.

The next mm lines each contain three integers ui,vi,wiu_i, v_i, w_i (1≤ui,vi≤n1 \le u_i, v_i \le n, ui≠viu_i \neq v_i, 1≤wi≤1041 \le w_i \le 10^4), indicating a bidirectional edge of length wiw_i between uiu_i and viv_i.

The next line contains an integer kk (0≤k≤180 \le k \le 18), the number of bikes.

The next kk lines each contain two integers ai,pia_i, p_i (1≤ai≤n1 \le a_i \le n, 0≤pi≤1000 \le p_i \le 100), 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 10−610^{-6} 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 1→31 \rightarrow 3 to try the only bike on campus.
  • If the bike is broken, walk along the route 3→1→2→43 \rightarrow 1 \rightarrow 2 \rightarrow 4, 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 21002100. So the time cost is 21003=700\frac{2100}{3} = 700.

If the bike is not broken, you walk along 1→31 \rightarrow 3, total length 300300, then ride the bike along 3→1→2→43 \rightarrow 1 \rightarrow 2 \rightarrow 4, total length 18001800. So the time cost is 3003+180015=220\frac{300}{3} + \frac{1800}{15} = 220.

The bike is broken with probability 50100\frac{50}{100}. So the expected time cost is $\frac{50}{100} \times 700 + (1 - \frac{50}{100}) \times 220 = 460$.