Dual Core CPU
Dual Core CPU
Time Limit: 15000MS Memory Limit: 131072K
Total Submissions: 20935 Accepted: 9054
Case Time Limit: 5000MS
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 1
1 10
2 10
10 3
2 3 1000
Sample Output
13
Source
POJ Monthly–2007.11.25, Zhou Dong
将CPU1看成源点,将CPU2看成汇点,对于每个模块建立与源点和汇点容量弧,将不同模块a,b的额外花费建立容量为w的弧,建立起容量网络
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstdio>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define PI acos(-1.0)
#define MMM 0x3f3f3f3f
#define RR freopen("input.txt","r",stdin)
#define WW freopen("output.txt","w",stdout)
const int INF = 0x3f3f3f3f;
const int Max = 1000000;
struct Edge
{
int v;
int cap;
int next;
}E[Max];
int top;
int n,m;
int Head[21000];
int Du[21000];
void Build(int u,int v,int w,int ww)
{
E[top].v=v; E[top].cap=w;
E[top].next=Head[u];
Head[u]=top++;
E[top].v=u; E[top].cap=ww;
E[top].next=Head[v];
Head[v]=top++;
}
bool bfs()
{
memset(Du,0,sizeof(Du));
Du[0]=1;
queue<int>Q;
Q.push(0);
while(!Q.empty())
{
int a=Q.front();
Q.pop();
for(int i=Head[a];i!=-1;i=E[i].next)
{
if(Du[E[i].v]==0&&E[i].cap>0)
{
Du[E[i].v]=Du[a]+1;
Q.push(E[i].v);
}
}
}
return Du[n+1];
}
int dfs(int star,int num)
{
if(star==n+1||num==0)
{
return num;
}
int s=0;
int ant;
for(int i=Head[star];i!=-1;i =E[i].next)
{
if(Du[star]+1==Du[E[i].v]&&(ant=dfs(E[i].v,min(num,E[i].cap)))>0)
{
E[i].cap-=ant;
num-=ant;
s+=ant;
E[i^1].cap+=ant;
if(num==0)
{
break;
}
}
}
return s;
}
int Dinic()
{
int ant=0;
while(bfs())
{
ant+=dfs(0,INF);
}
return ant;
}
int main()
{
int u,v,w,a,b;
while(~scanf("%d %d",&n,&m))
{
top=0;
memset(Head,-1,sizeof(Head));
for(int i=1;i<=n;i++)
{
scanf("%d %d",&a,&b);
Build(0,i,a,0);
Build(i,n+1,b,0);
}
for(int i=1;i<=m;i++)
{
scanf("%d %d %d",&u,&v,&w);
Build(u,v,w,w);
}
printf("%d\n",Dinic());
}
return 0;
}
Dual Core CPU的更多相关文章
- poj 3469 Dual Core CPU【求最小割容量】
Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 21453 Accepted: 9297 ...
- POJ 3469.Dual Core CPU 最大流dinic算法模板
Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 24830 Accepted: 10756 ...
- POJ 3469 Dual Core CPU Dual Core CPU
Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 23780 Accepted: 10338 Case Time Lim ...
- poj3469 Dual Core CPU
Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 25576 Accepted: 11033 ...
- POJ 3469 Dual Core CPU (最小割建模)
题意 现在有n个任务,两个机器A和B,每个任务要么在A上完成,要么在B上完成,而且知道每个任务在A和B机器上完成所需要的费用.然后再给m行,每行 a,b,w三个数字.表示如果a任务和b任务不在同一个机 ...
- poj 3469 Dual Core CPU
题目描述:由于越来越多的计算机配置了双核CPU,TinySoft公司的首席技术官员,SetagLilb,决定升级他们的产品-SWODNIW.SWODNIW包含了N个模块,每个模块必须运行在某个CPU中 ...
- poj 3469 Dual Core CPU 最小割
题目链接 好裸的题....... 两个cpu分别作为源点和汇点, 每个cpu向元件连边, 权值为题目所给的两个值, 如果两个元件之间有关系, 就在这两个元件之间连边, 权值为消耗,这里的边应该是双向边 ...
- 【做题】POJ3469 Dual Core CPU——第一道网络流
刚学了Dinic就开始做题,然后就崩了. 题意:若干个任务,可以放在两个CPU中任意一个上完成,各有一定代价.其中又有若干对任务,如果它们不在同一个CPU上完成,会产生额外代价.最小化并输出代价. 一 ...
- POJ3469:Dual Core CPU——题解
http://poj.org/problem?id=3469 题目大意: 两个CPU,处理每个任务有不同的代价,有些对任务如果不在同一个CPU就会增加代价,求最小代价. ——————————————— ...
随机推荐
- Swift游戏实战-跑酷熊猫 12 与平台的碰撞
这节主要实现熊猫和平台的碰撞,实现熊猫在平台上奔跑 要点 对平台进行物理属性设置 //设置物理体以及中心点 self.physicsBody = SKPhysicsBody(rectangleOfSi ...
- Swift游戏实战-跑酷熊猫 09 移除场景之外的平台
上一节,我们写出了一个疯狂产生平台的东西.所谓上帝欲使其灭亡,必先使其疯狂.所以太疯狂都不是什么好事,所以我们要采取一些措施,例如移除场景之外的平台.btw如果哪天你觉得自己的老板行为乖张,难以理喻. ...
- ads 错误
这个问题已经不是第一次碰到了,每次弄周立功的EasyARM2210的时候都会遇见,每次都没有记住.就是要用ADS运行板子配套光盘里面的配套程序的时候会出现: (Fatal)L6002U:Could n ...
- SQL top查询
select *from emp;
- ofbiz进击 第四节。 我的form之旅
一般使用ofbiz做后台管理的时候,多数会使用ofbiz的form去做后台.下面我就总结下我在使用form的时候的一些总结与问题吧. 1.首先,我们看如何使用最简单form去查询某个单个的对象,并对其 ...
- (转)supertable像excel那样固定table的表头和第一列
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"/> <title> ...
- ppaer 67 : matlab 函数errorbar
MATLAB ERRORBAR 这个函数的意思是:ERRORBAR(X,Y,L,U),X是自变量,Y是因变量,L是Y的变动下限,U是Y的变动上限 errorbar(X,Y,E) X是自变量,Y是因变 ...
- C#.Net GC(garbage Collector) 垃圾回收器
以前一直以为gc的原理很简单,也就是分代处理堆数据,直到我的膝盖中了一箭(好吧 直到有天汪涛和我说他面试携程的面试题 关于服务器和 工作站gc 的区别)其实我当时尚不知道 工作站和服务器有什么区别更不 ...
- DOM事件处理有三个阶段
DOM事件处理有三个阶段: 捕捉阶段(capture phase):从最上层元素,直到最下层(你点击的那个target)元素.路过的所有节点都可以捕捉到该事件. 命中阶段(target phase): ...
- rails控制台进入
数据库控制台: rails db .help查看可使用的命令 rails控制台 rails c 普通ruby控制台: irb