#P2494. [SDOI2011] 保密

    ID: 1508 远端评测题 2000ms 125MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2011各省省选山东最大流分数规划

[SDOI2011] 保密

Description

Nowadays, secrecy has become very important and also very difficult. If it is not done well, the consequences can be serious. For example, someone did not repair their computer themselves and did not remove the hard drive—what happened afterward is known to everyone.

Of course, the military needs secrecy the most, more than ordinary people. To cope with satellites flying around in the sky, military bases are usually built underground.

A certain base in country K is structured as follows: on the ground, there are two rows of large shafts serving as entrances and exits, with a total of n1n_1. Inside, there are many cavities that are mutually disconnected except that they can share entrances. Each cavity has exactly two entrances, and these two entrances are not in the same row. For convenience, the entrances in the two rows are numbered 1,3,5,1, 3, 5, \dots and 2,4,6,2, 4, 6, \dots, and the largest index is n1n_1.

Although we have talked so much about secrecy, decryption is also a tangled matter. In fact, the simplest brute-force decryption method is to send someone to have a look...

We have elite special forces. If you deploy one unit to some entrance of the base in country K, then all cavities directly connected to that entrance can be explored by that unit, and only those cavities can be explored by that unit. Now you have enough units at your disposal, and you must use them to explore all cavities inside the base in country K.

Your base is not too close to the base in country K. You are given a map of the surrounding area, represented by nn checkpoints and mm roads connecting these points. Points 11 through n1n_1 are the entrances to the base in country K, and point nn is the starting point of your units. For each road, there is a travel time tt and a safety factor ss. Because the intelligence department assessed safety only for one-way roads, these roads are one-way only, and there are no cycles.

A unit departs from your base, follows some path, and reaches an entrance of the base in country K. The risk of this unit is defined as the ratio of the total time to the sum of the safety factors of all roads along that path. The overall operation risk is the sum of the risks of all the units you dispatch. You need to explore the entire base in country K while minimizing this value.

Hurry up and finish this task before a certain professor in country K declares that you are from country K.

Input Format

The first line contains two positive integers n,mn, m, the number of checkpoints and roads on the map.

Each of the next mm lines contains four positive integers a,b,t,sa, b, t, s, indicating a one-way road from aa to bb with travel time tt and safety factor ss.

The next line contains two positive integers m1m_1 and n1n_1, where m1m_1 is the number of cavities in the base in country K, and n1n_1 is the number of entrances.

Each of the next m1m_1 lines contains two positive integers u,vu, v, indicating the two entrances of each cavity.

Output Format

Output one line with the minimum total risk, to one decimal place. Output -1 if the task is impossible.

5 5
5 1 10 1
5 1 10 1
5 2 9 1
5 3 7 1
5 4 8 1
4 4
1 2
1 4
3 2
3 4
17.0

Hint

  • For 30% of the testdata, n30n \leq 30.
  • For 60% of the testdata, n300n \leq 300.
  • For an additional 40% of the testdata, n120n_1 \leq 20.
  • For 100% of the testdata: 4n7004 \leq n \leq 700, m100000m \leq 100000, a,bna, b \leq n, 1t,s101 \leq t, s \leq 10, m140000m_1 \leq 40000, n1<min(n,161)n_1 < \min(n, 161), u,vn1u, v \leq n_1, uu is odd, and vv is even.

Translated by ChatGPT 5