POJ 3469.Dual Core CPU 最大流dinic算法模板
| Time Limit: 15000MS | Memory Limit: 131072K | |
| Total Submissions: 24830 | Accepted: 10756 | |
| 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
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
#define PI acos(-1.0)
typedef long long ll;
typedef pair<int,int> P;
const int maxn=1e5+,maxm=1e5+,inf=0x3f3f3f3f,mod=1e9+;
const ll INF=1e18+;
priority_queue<P,vector<P>,greater<P> >que;
struct edge
{
int from,to;
int cap;
int rev;///方向边的编号
};
vector<edge>G[maxn];///邻接表存图
int iter[maxn];///当前弧,在其之前的边已经没有了作用
int level[maxn];///层次
void addedge(int u,int v,int c)
{
edge e;
e.from=u,e.to=v,e.cap=c,e.rev=G[v].size();
G[u].push_back(e);
e.from=v,e.to=u,e.cap=,e.rev=G[u].size()-;
G[v].push_back(e);
}
int bfs(int s,int t)
{
memset(level,-,sizeof(level));
queue<int>q;
level[s]=;
q.push(s);
while(!q.empty())
{
int u=q.front();
q.pop();
for(int i=; i<G[u].size(); i++)
{
edge e=G[u][i];
if(e.cap>&&level[e.to]<)
{
level[e.to]=level[u]+;
q.push(e.to);
}
}
}
if(level[t]<) return ;
else return ;
}
int dfs(int u,int t,int f)
{
if(u==t||f==) return f;
int flow=;
for(int &i=iter[u]; i<G[u].size(); i++)
{
edge e=G[u][i];
if(e.cap>&&level[u]+==level[e.to])
{
int d=dfs(e.to,t,min(f,e.cap));
if(d>)
{
G[u][i].cap-=d;
G[e.to][e.rev].cap+=d;
flow+=d;
f-=d;
if(f==) break;
}
}
}
return flow;
}
int max_flow(int s,int t)
{
int flow=;
while(bfs(s,t))
{
memset(iter,,sizeof(iter));
flow+=dfs(s,t,inf);
}
return flow;
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int s=,t=n+;
for(int i=; i<=n; i++)
{
int a,b;
scanf("%d%d",&a,&b);
addedge(s,i,a);
addedge(i,t,b);
}
for(int i=; i<=m; i++)
{
int a,b,w;
scanf("%d%d%d",&a,&b,&w);
addedge(a,b,w);
addedge(b,a,w);
}
cout<<max_flow(s,t)<<endl;
return ;
}
最大流模板
POJ 3469.Dual Core CPU 最大流dinic算法模板的更多相关文章
- 【网络流#8】POJ 3469 Dual Core CPU 最小割【ISAP模板】 - 《挑战程序设计竞赛》例题
		
[题意]有n个程序,分别在两个内核中运行,程序i在内核A上运行代价为ai,在内核B上运行的代价为bi,现在有程序间数据交换,如果两个程序在同一核上运行,则不产生额外代价,在不同核上运行则产生Cij的额 ...
 - POJ 3469	Dual Core CPU 最大流
		
划分成两个集合使费用最小,可以转成最小割,既最大流. //#pragma comment(linker, "/STACK:1024000000,1024000000") #incl ...
 - poj 3469 Dual Core CPU【求最小割容量】
		
Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 21453 Accepted: 9297 ...
 - POJ 3469 Dual Core CPU Dual Core CPU
		
Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 23780 Accepted: 10338 Case Time Lim ...
 - POJ 3469 Dual Core CPU (最小割建模)
		
题意 现在有n个任务,两个机器A和B,每个任务要么在A上完成,要么在B上完成,而且知道每个任务在A和B机器上完成所需要的费用.然后再给m行,每行 a,b,w三个数字.表示如果a任务和b任务不在同一个机 ...
 - POJ 3469 Dual Core CPU(最小割)
		
[题目链接] http://poj.org/problem?id=3469 [题目大意] 有N个模块要在A,B两台机器上执行,在不同机器上有不同的花费 另有M个模块组(a,b),如果a和b在同一台机子 ...
 - poj 3469 Dual Core CPU——最小割
		
题目:http://poj.org/problem?id=3469 最小割裸题. 那个限制就是在 i.j 之间连双向边. 根据本题能引出网络流中二元关系的种种. 别忘了写 if ( x==n+1 ) ...
 - poj 3469 Dual Core CPU
		
题目描述:由于越来越多的计算机配置了双核CPU,TinySoft公司的首席技术官员,SetagLilb,决定升级他们的产品-SWODNIW.SWODNIW包含了N个模块,每个模块必须运行在某个CPU中 ...
 - poj 3469 Dual Core CPU  最小割
		
题目链接 好裸的题....... 两个cpu分别作为源点和汇点, 每个cpu向元件连边, 权值为题目所给的两个值, 如果两个元件之间有关系, 就在这两个元件之间连边, 权值为消耗,这里的边应该是双向边 ...
 
随机推荐
- mysql  触发器介绍
			
create trigger triggerName after/before insert/update/delete on tableName for each row --这句话在my ...
 - jquery滚动条平滑滑动
			
采用锚点进行页面中的跳转的确很方便,但是要想增加网页的效果,可以使用jquery中的animate,实现滚动的一个动作,慢慢的滚动到你想跳转到的位置,从而看起来会非常高大上. 滚动到顶部: $(' ...
 - linux服务器设置只允许密钥登陆
			
首先需要修改一些配置文件 vim /etc/ssh/sshd_config 进入sshd_config文件后需要更改几个地方 PubkeyAuthentication yes #启用公告密钥配对认证方 ...
 - 大数据入门到精通4--spark的rdd的map使用方式
			
学习了之前的rdd的filter以后,这次来讲spark的map方式 1.获得文件 val collegesRdd= sc.textFile("/user/hdfs/CollegeNavig ...
 - metasploit framework(六):信息收集
			
nmap 扫描 扫描完毕之后,hosts查看扫描的结果 auxiliary 扫描 使用arpsweep模块扫描 查看设置 设置网卡和目标IP 设置伪造的源IP和源MAC set SHOST <伪 ...
 - Mysql 单表操作、增删查改(基础4)
			
新建一个表,往里面插入数据. #新建一个表 mysql> create table test( -> id int, -> name varchar(20) -> );Quer ...
 - JMeter (二十)参数化、检查点、集合点(转载)
			
转载自 http://www.cnblogs.com/yangxia-test 参数化:简单的来理解一下,我们录制了一个脚本,这个脚本中有登录操作,需要输入用户名和密码,假如系统不允许相同的用户名和密 ...
 - 健壮的网络编程IO函数-RIO包
			
RIO包 简介 Rio包即为Robust io函数包.包中函数是对Linux基本I/O函数的封装,使其更加健壮.高效,更适用于网络编程. 分析 Rio包由rio_t结构体和系列函数组成. 首先是两个不 ...
 - TCP的状态转移
			
状态转移图 状态分析 客户端 CLOSED 初始状态 调用connect将发起主动打开,发送SYN J到服务端,进入SYN_SENT状态. SYN_SENT 客户端已经发送SYN报文 接收到服务端发回 ...
 - IronPython 的几个问题
			
1.在脚本中使用datagridview.Rows[i].Cells[1].Value并将其转换为string时,遇到int类型 有时可是直接使用.toString()转换为字符 有时必须采用str( ...