POJ 3469 Dual Core CPU ——网络流
【题目分析】
构造一个最小割的模型。
S向每一个点连Ai,每一个点向T连Bi。
对于每一个限制条件,在i和j之间连一条Cij的双向边即可。
然后求出最小割就是最少的花费。
验证最小割的合理性很容易。
【代码】
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib> //#include <map>
#include <set>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 50005
#define ll long long
#define me 400005
#define inf 0x3f3f3f3f
#define F(i,j,k) for (int i=j;i<=k;++i)
#define D(i,j,k) for (int i=j;i>=k;--i) void Finout()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif
} int Getint()
{
int x=0,f=1; char ch=getchar();
while (ch<'0'||ch>'9') {if (ch=='-') f=-1; ch=getchar();}
while (ch>='0'&&ch<='9') {x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
int h[me<<1],to[me<<1],ne[me<<1],fl[me<<1],en=0,S=0,T=me-1; void add(int a,int b,int c)
{
to[en]=b; ne[en]=h[a]; fl[en]=c; h[a]=en++;
// to[en]=a; ne[en]=h[b]; fl[en]=0; h[b]=en++;
} int map[me]; bool tell()
{
queue <int> q;
memset(map,-1,sizeof map);
map[S]=0;
while (!q.empty()) q.pop();
q.push(S);
while (!q.empty())
{
int x=q.front(); q.pop();
for (int i=h[x];i>=0;i=ne[i])
{
if (map[to[i]]==-1&&fl[i]>0)
{
map[to[i]]=map[x]+1;
q.push(to[i]);
}
}
}
if (map[T]!=-1) return true;
return false;
} int zeng(int k,int r)
{
if (k==T) return r;
int ret=0;
for (int i=h[k];i>=0&&ret<r;i=ne[i])
if (map[to[i]]==map[k]+1&&fl[i]>0)
{
int tmp=zeng(to[i],min(fl[i],r-ret));
ret+=tmp; fl[i]-=tmp; fl[i^1]+=tmp;
}
if (!ret) map[k]=-1;
return ret;
} int main()
{
memset(h,-1,sizeof h);
Finout();
int n,m,a,b,c;
n=Getint();m=Getint();
F(i,1,n)
{
a=Getint(); b=Getint();
add(S,i,a);
add(i,S,0);
add(i,T,b);
add(T,i,0);
}
F(i,1,m)
{
a=Getint(); b=Getint();
c=Getint();
add(a,b,c);
add(b,a,c);
}
int ans=0,tmp;
while (tell()) while (tmp=zeng(S,inf)) ans+=tmp;
cout<<ans<<endl;
}
POJ 3469 Dual Core CPU ——网络流的更多相关文章
- 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 ...
- poj 3469 Dual Core CPU【求最小割容量】
Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 21453 Accepted: 9297 ...
- 【网络流#8】POJ 3469 Dual Core CPU 最小割【ISAP模板】 - 《挑战程序设计竞赛》例题
[题意]有n个程序,分别在两个内核中运行,程序i在内核A上运行代价为ai,在内核B上运行的代价为bi,现在有程序间数据交换,如果两个程序在同一核上运行,则不产生额外代价,在不同核上运行则产生Cij的额 ...
- poj 3469 Dual Core CPU——最小割
题目:http://poj.org/problem?id=3469 最小割裸题. 那个限制就是在 i.j 之间连双向边. 根据本题能引出网络流中二元关系的种种. 别忘了写 if ( x==n+1 ) ...
- POJ 3469 Dual Core CPU(最小割)
[题目链接] http://poj.org/problem?id=3469 [题目大意] 有N个模块要在A,B两台机器上执行,在不同机器上有不同的花费 另有M个模块组(a,b),如果a和b在同一台机子 ...
- 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向元件连边, 权值为题目所给的两个值, 如果两个元件之间有关系, 就在这两个元件之间连边, 权值为消耗,这里的边应该是双向边 ...
随机推荐
- strophe.js 插件 XMPP openfire
参考资料:http://strophe.im/strophejs/ https://github.com/strophe/strophejs-plugins http://amazeui.org/ 最 ...
- codevs 2038 香甜的黄油 USACO
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 农夫John发现做出全威斯康辛州最甜的黄油的方法:糖.把糖放在一片牧场上 ...
- Bellman-Ford与SPFA
一.Bellman-Ford Bellman-Ford 算法是一种用于计算带权有向图中单源最短路径(当然也可以是无向图).与Dijkstra相比的优点是,也适合存在负权的图. 若存在最短路(不含负环时 ...
- vue watch 监听
1.普通的watch data() { return { frontPoints: 0 } }, watch: { frontPoints(newValue, oldValue) { console. ...
- url编码和解码平台
http://meyerweb.com/eric/tools/dencoder/
- PJSIP-iOS源码编译
官方文档https://trac.pjsip.org/repos/wiki/Getting-Started/iPhone 功能 在iPhone上可以实现的功能: 包含基于CoreAudio的音频设备, ...
- CPP-基础:C++拷贝构造函数详解
一. 什么是拷贝构造函数 首先对于普通类型的对象来说,它们之间的复制是很简单的,例如: ; int b = a; 而类对象与普通对象不同,类对象内部结构一般较为复杂,存在各种成员变量.下面看一个类对象 ...
- Codeforces Round #273 (Div. 2)-B. Random Teams
http://codeforces.com/contest/478/problem/B B. Random Teams time limit per test 1 second memory limi ...
- metasploit-shellcode生成
0x00 安装metasploit $ curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/t ...
- HTML5拖放(drag和drog)作品
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...