Coding Contest
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 5337 Accepted Submission(s): 1256
Problem Description
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 ui-th block to the vi-th block. Your task is to solve the lunch issue. According to the arrangement, there are sicompetitors in the i-th block. Limited to the size of table, bi 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 pi to touchthe wires and affect the whole networks. Moreover, to protect these wires, no more than ci 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 bi (si , bi ≤ 200).Each of the next M lines contains three integers ui , vi and ci(ci ≤ 100) and a float-point number pi(0 < pi < 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
Source
求网络被破坏的最小可能性,因为是乘法,所以要用取对数的方法把它改成加法。
因为概率是小于1的,所以取对数完是负数,需要用 - 把它转为正数。
但是转为正数后,原来的最小值就会变为最大值,所以用p=-log2(1-p),转为求不被破坏的最大可能行,跑费用流
因为是浮点型,所以在松弛的时候要加上eps。
最后,要用for去代替memset,不然可能会t...
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 9 const double eps=1e-9; 10 const int INF=0x3f3f3f3f; 11 const int N=500005; 12 const int M=500005; 13 int top; 14 double dist[N]; 15 int pre[N]; 16 bool vis[N]; 17 int c[N]; 18 int maxflow; 19 20 struct Vertex{ 21 int first; 22 }V[N]; 23 struct Edge{ 24 int v,next; 25 int cap,flow; 26 double cost; 27 }E[M]; 28 29 void init(int num){ 30 // memset(V,-1,sizeof(V)); 31 for(int i=0;i