云原生 API 网关 APISIX入门
331
2022-08-30
POJ 3469:Dual Core CPU (最大流)
Description
As more and more computers are equipped with dual core CPU, SetagLilb, the Chief Technology Officer of TinySoft Corporation, decided to update their famous product - SWODNIW.The routine consists of N modules, and each of them should run in a certain core. The costs for all the routines to execute on two cores has been estimated. Let’s define them as Ai and Bi. Meanwhile, M pairs of modules need to do some data-exchange. If they are running on the same core, then the cost of this action can be ignored. Otherwise, some extra cost are needed. You should arrange wisely to minimize the total cost.
Input
There are two integers in the first line of input data, N and M (1 ≤ N ≤ 20000, 1 ≤ M ≤ 200000) .The next N lines, each contains two integer, Ai and Bi.In the following M lines, each contains three integers: a, b, w. The meaning is that if module a and module b don’t execute on the same core, you should pay extra w dollars for the data-exchange between them.
Output
Output only one integer, the minimum total cost.
Sample Input
3 11 102 1010 32 3 1000
Sample Output
13
题意
有n个模块,每个模块在A上花费ai,在B上花费bi,然后有m个任务(ai,bi,wi),如果ai,bi不在一起工作的话需要额外花费wi,求最小花费。
思路
开始想了很久如何建图可以求得最小花费,最后发现它其实是一个最小割模型。
将网络里的模块划分成s-t两个点集,然后需要合适的方法去构建这个最小割模型。
对于每一个模块,考虑它在A集时,花费为ai,便从s出发连接一条ai的边,考虑它在B集时,花费为bi,便向t连接一条bi的边,而最终对于每一个任务,因为当ai与bi不同的时候会增加额外花费,所以在ai与bi之间连接一条wi的双向边。
题目中的最小花费,可以很轻松的发现它其实是我们构建出这个图的最小割,根据最大流最小割定理,我们只需要求出从源点s到汇点t的最大流便可。
AC代码
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~