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向元件连边, 权值为题目所给的两个值, 如果两个元件之间有关系, 就在这两个元件之间连边, 权值为消耗,这里的边应该是双向边 ...
随机推荐
- jquery iframe父子框架中的元素访问方法
在web开发中,经常会用到iframe,难免会碰到需要在父窗口中使用iframe中的元素.或者在iframe框架中使用父窗口的元素 js 在父窗口中获取iframe中的元素 1. 格式:window. ...
- mongo的csv文件参考
https://blog.csdn.net/u012318074/article/details/77713228
- java工程师基础笔试题(一)-参考答案
一.选择和填空 (不定项哦!) 1,如下是一份文件名为Test2.java的源文件,请问,编译该文件之后会生成几份字节码文件 class Test{ class Inner{} static cla ...
- javascript学习笔记(一):基础、输出、注释、引用、变量、数据类型
javascript脚本必须位于<script></script>之间,<script>标签可以位于<head>中,也可以位于<body>中 ...
- angularjs directive scope 与父scope双向绑定
参考 http://www.jb51.net/article/83051.htm angluar.module("aaa").directive("testDirecti ...
- mysql分组GROUP BY常用sql
数据分组 GROUP BY GROUP BY可以根据一个或多个字段进行分组. 比如,根据prod_id分组: SELECT prod_id ,user_id FROM products GROUP B ...
- VHS介绍
Java.JS HTTP流传输(VHS)介绍“我怎么才能让我的视频和Video.js一起玩?”“ 这是我们在使用Vio.js时最常见的问题之一.这是个好问题. 如果有人检查了Vo.js的拷贝,他们的内 ...
- leetcode 树类型题
树的测试框架: // leetcodeTree.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream& ...
- pta7-7旅游规划(dijkstra算法)
题目链接:https://pintia.cn/problem-sets/1101307589335527424/problems/1101314114762387456 题意:给n给城市,m条公路,公 ...
- pandas数据处理攻略
首先熟悉numpy随机n维数组的生成方法(只列出常用的函数): np.random.random([3, 4]) #生成shape为[3, 4]的随机数组,随机数范围[0.0, 1.0) np.ran ...