1. 程式人生 > >5988 (運用log轉乘法為加法,費用流)

5988 (運用log轉乘法為加法,費用流)

Coding Contest

A coding contest will be held in this university, in a huge playground. The whole playground would be divided into N blocks, and there would be M directed paths linking these blocks. The i-th path goes from the uiui-th block to the vivi-th block. Your task is to solve the lunch issue. According to the arrangement, there are sisicompetitors in the i-th block. Limited to the size of table, bibi bags of lunch including breads, sausages and milk would be put in the i-th block. As a result, some competitors need to move to another block to access lunch. However, the playground is temporary, as a result there would be so many wires on the path.  For the i-th path, the wires have been stabilized at first and the first competitor who walker through it would not break the wires. Since then, however, when a person go through the i - th path, there is a chance of pipi to touch  the wires and affect the whole networks. Moreover, to protect these wires, no more than cici competitors are allowed to walk through the i-th path.  Now you need to find a way for all competitors to get their lunch, and minimize the possibility of network crashing. 

Input

The first line of input contains an integer t which is the number of test cases. Then t test cases follow.  For each test case, the first line consists of two integers N (N ≤ 100) and M (M ≤ 5000). Each of the next N lines contains two integers si and bibi (sisi , bibi ≤ 200).  Each of the next M lines contains three integers uiui , vivi and ci(cici(ci ≤ 100) and a float-point number pipi(0 < pipi < 1).  It is guaranteed that there is at least one way to let every competitor has lunch.

Output

For each turn of each case, output the minimum possibility that the networks would break down. Round it to 2 digits.

Sample Input

1
4 4
2 0
0 3
3 0
0 3
1 2 5 0.5
3 2 5 0.5
1 4 5 0.5
3 4 5 0.5

Sample Output

0.50

題目大意:

給出一張圖,圖上的每個點有si個選手,bi份食物,有的點之間用有最多可以通過ci個選手,除第一次外每次通過選手都有pi概率使全圖斷裂的邊連線。問如何讓選手走動可以使他們都吃到東西而且全圖斷裂的可能最小。

思路:

圖斷裂的概率為1-\prod(1-pi)^(wi-1),wi為通過的人數。要求概率最小,那就是求\prod(1-pi)^(wi-1)的最大值,用log處理之後這就是一個簡單的加法處理了。直接套用MCMF的板子就完事了。

反思:最近練了很短網路流了,可是今天做這題的時候還是沒有做出來。反思一下自己