hdu 5988 Coding Contest(最小费用最大流)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5988

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 si competitors 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 touch
the 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.

扫描二维码关注公众号,回复: 3859283 查看本文章

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

浮点数在spfa时候,注意一个是eps,一个是dis开double   不然tle!!!!!!!!!!!!坑死

		num[i] = u - v;
		}
		int u, v, f;
		double p;
		for (int i = 1; i <= m; i++)
		{
			scanf("%d%d%d%lf", &u, &v, &f, &p);
			p = -log2(1.0 - p);
			if (f > 0)
			{
				addedge(u, v, 1, 0.0);
			}
			if (f - 1 > 0)
			{
				addedge(u, v, f - 1, p);
			}
		}
		for (int i = 1; i <= n; i++)
		{
			if (num[i] > 0)
			{
				addedge(0, i, num[i], 0);
			}
			else
			{
				addedge(i, n + 1, -num[i], 0);
			}
		}
		double ans = 0;
		dinic(0, n + 1, ans);
		ans = pow(2, -ans);
		printf("%.2f\n", 1.0 - ans);
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/Evildoer_llc/article/details/83247594