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就会增加代价,求最小代价. ——————————————— ...
随机推荐
- OLTP与OLAP的差异
OLTP与OLAP的差异 系统类型 OLTP(在线交易系统) OLAP(联机分析系统),DW(数据仓库) 数据来源 操作数据,OLTP通常是原始性数据源 联合型数据:OLAP数据来源于其他OLTP系统 ...
- 成员变量&&局部变量
一.相同点:1.都遵循变量的声明格式:(修饰符) 数据类型 变量名=初始化值 2.都有各自的作用域 二.不同点:1.声明的位置不同 成员变量:声明在类内,方法外. 局部变量:声明在方法内. ...
- 转:python webdriver API 之简单对象的定位
对象(元素)的定位和操作是自动化测试的核心部分,其中操作又是建立在定位的基础上的,因此元素定位就显得非常重要. (本书中用到的对象与元素同为一个事物)一个对象就像是一个人,他会有各种的特征(属性) , ...
- Git 代码管理常用命令
1) 远程仓库相关命令 检出仓库:$ git clone git://github.com/jquery/jquery.git查看远程仓库:$ git remote -v添加远程仓库:$ git re ...
- Codeforces Round #284 (Div. 1)
A. Crazy Town 这一题只需要考虑是否经过所给的线,如果起点和终点都在其中一条线的一侧,那么很明显从起点走点终点是不需要穿过这条线的,否则则一定要经过这条线,并且步数+1.用叉积判断即可. ...
- 关于 static 的用途
1.三个作用 第一个作用是 隐藏 输出: Hello 所有未加static前缀的全局变量和函数都具有全局可见性,其它的源文件也能访问.此例中,a是全局变量,msg是函数,并且都没有加static前缀, ...
- sql over开窗函数,
sql over开窗函数, 1.使用over子句与rows_number()以及聚合函数进行使用,可以进行编号以及各种操作.而且利用over子句的分组效率比group by子句的效率更高. 2.在订单 ...
- oracle查询表的索引
select * from user_indexes where table_name='表名'; select * from user_ind_columns where index_name='索 ...
- json转化为java实体
import net.sf.json.JSONObject; Map<String, Object> classMap = new HashMap<String, Object> ...
- z/os上的tar和gzip
在*nix平台上玩过的人都知道,tar和gzip基本上是每天都要使用的,而且非常之好用.而Mainframer则比较痛苦,没有这么好用的东西,尤其是当需要通过网络传大批量的文件的时候很不方便. 不过总 ...