#P2494. [SDOI2011] 保密
[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 . 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 and , and the largest index is .
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 checkpoints and roads connecting these points. Points through are the entrances to the base in country K, and point is the starting point of your units. For each road, there is a travel time and a safety factor . 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 , the number of checkpoints and roads on the map.
Each of the next lines contains four positive integers , indicating a one-way road from to with travel time and safety factor .
The next line contains two positive integers and , where is the number of cavities in the base in country K, and is the number of entrances.
Each of the next lines contains two positive integers , 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, .
- For 60% of the testdata, .
- For an additional 40% of the testdata, .
- For 100% of the testdata: , , , , , , , is odd, and is even.
Translated by ChatGPT 5
京公网安备 11011102002149号