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就会增加代价,求最小代价. ——————————————— ...
随机推荐
- javabean实体类对象转为Map类型对象的方法(转发)
//将javabean实体类转为map类型,然后返回一个map类型的值 public static Map<String, Object> beanToMap(Object obj) { ...
- web 前端:连接mysql中文乱码问题的解决办法
当使用tomcat部署servlet连接时,总是出现各种原因的中文乱码问题.有的是因为mysql的默认字符集的问题,有的是客户端的字符配置问题. 现在对于这两种问题进行配置,来解决乱码. 服务器端(m ...
- HTML调用servlet(一)
1.页面的数据表单 在使用Servlet处理用户请求之前,先准备一个页面,该页面用来提供数据表单.数据表单就是HTML中的<form>...</form>部分,当用户单击Sub ...
- git的基本使用
1.在本地新建一个文件夹来存放代码 2.用命令行进入这个文件夹 3.git init --来创建一个代码仓库 3. 配置用户信息:用户名和 邮箱(联系作者本人沟通, 责任到人) git config ...
- Ruby操作VBA的注意事项和技巧(2):宏里调用和控制窗体以及窗体上的控件、不同workbook之间的宏互相调用
4.宏里调用并控制窗体以及窗体上的各种控件 1 Sub Criterion_Check() 2 If Workbooks.count = 0 Then '如果当前没有打开的工作薄的话需要发出警告 3 ...
- POJ 2417 Discrete Logging(离散对数-小步大步算法)
Description Given a prime P, 2 <= P < 231, an integer B, 2 <= B < P, and an integer N, 1 ...
- Codeforces Beta Round #93 (Div. 1 Only) D. Fibonacci Sums
先考虑一个斐波那契数能分成其他斐波那契数的方案,假如f[i]表示第i个斐波那契数,那么只要对他进行拆分,f[i-1]这个数字必定会存在.知道这一点就可以进行递推了.先将数字分成最少项的斐波那契数之和, ...
- 同时启动多个Tomcat
一,修改配置文件server.xml的端口 C:\apache-tomcat-5.5.23-1\conf\server.xml用记事本什么的打开修改3个地方 第一: <Server port ...
- 14---Net基础加强
更新中,敬请期待............ 复习-匿名类型 Xml介绍
- PAT乙级 1021. 个位数统计 (15)
1021. 个位数统计 (15) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 给定一个k位整数N = dk-1 ...