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向元件连边, 权值为题目所给的两个值, 如果两个元件之间有关系, 就在这两个元件之间连边, 权值为消耗,这里的边应该是双向边 ...
随机推荐
- LinQ to sql简介及增删改查
Linq to sql 类 LinQ它就是一个集成化的数据库访问类,它会自动生成许多原本需要我们自己创建的东西: 它和ADO.NET是一样的东西,都是为了访问数据库而出现的,EF框架 一.创建LinQ ...
- HTML表格与表单复习
1.表格 <table></table> 表格 width:宽度.可以用像素或百分比表示.常用960像素. border:边框.常用值0. cellpadding:内容跟单元格 ...
- Winform 学生管理系统增删改查
数据库: create database adonet go use adonet go create table xue ( code ), name ), sex bit, birth datet ...
- ARM9/ARM11/Cortex A8处理器(转载) .
//toppic:推荐几个值得中小企业使用的ARM9/ARM11/Cortex A8处理器 // 作者:gooogleman //原文地址:http://blog.csdn.net/goooglema ...
- js中基本事件的总结,onclick、onblur、onchange等
js中的基本事件总结: 特定的场景下发生的一个动作:事件:事件=函数(),事件发生会触发函数执行. 属性 当以下情况发生时,出现此事件 FF N IE onabort 图像加载被中断 1 3 4 on ...
- 径向模糊(Radial Blur)
[径向模糊(Radial Blur)] 径向模糊,是一种从中心向外呈幅射状的逐渐模糊的效果,在图形处理软件photoshop里面也有这个模糊滤镜.而在游戏中常常用来模拟一些动感的效果,如鬼泣4中的场景 ...
- STO单没有取进FP,IN_SAELS_ORDER表无,但IN_PO_STO有
描述 :业务反馈STO单没有取进FP,经检查IN_SALES_ORDER表没有此单数据,但在IN_PO_STO表却有 跟进如下: 1.检查IN_PO_STO表是否有数据 '; 2.检查SAP_SALE ...
- 二、Adapter 适配器
适配器:继承适配与委托适配 需求:Banner 可以输出强电流380v.弱电流12v,但是不能被直接使用.通过别的方式,介间的使用banner? 委托类图: 代码清单: 需要隐藏的功能类: publi ...
- numpy--深度学习中的线代基础
参考自 微信公众号--深度学习世界(http://mp.weixin.qq.com/s?__biz=MzI4MDMwMDM3NA==&mid=2247484616&idx=1& ...
- 【C++】STL算法之remove_if
之前写过这样一段代码: auto iter=remove_if(AllEdges.begin(),AllEdges.end(),[&](Edge* edge){return _isEedge( ...