POJ 3469 Dual Core CPU 最大流
划分成两个集合使费用最小,可以转成最小割,既最大流。
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<sstream>
#include<cmath>
#include<climits>
#include<string>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define pb(a) push(a)
#define INF 0x1f1f1f1f
#define lson idx<<1,l,mid
#define rson idx<<1|1,mid+1,r
#define PI 3.1415926535898
template<class T> T min(const T& a,const T& b,const T& c)
{
return min(min(a,b),min(a,c));
}
template<class T> T max(const T& a,const T& b,const T& c)
{
return max(max(a,b),max(a,c));
}
void debug()
{
#ifdef ONLINE_JUDGE
#else
freopen("data.in","r",stdin);
// freopen("d:\\out1.txt","w",stdout);
#endif
}
int getch()
{
int ch;
while((ch=getchar())!=EOF)
{
if(ch!=' '&&ch!='\n')return ch;
}
return EOF;
} struct Edge
{
int to,cap;
};
const int maxn = ;
vector<int> g[maxn];
vector<Edge> edge;
int n,m,s,t;
int d[maxn];
int vis[maxn];
int cur[maxn]; void add(int u,int v,int cap)
{
//printf("%d -> %d : %d\n", u, v, cap);
edge.push_back((Edge){v, cap});
g[u].push_back(edge.size() - );
edge.push_back((Edge){u, });
g[v].push_back(edge.size() - );
}
void build()
{
for(int i = ; i <= n; i++)
g[i].clear();
edge.clear();
s = n + ;
t = s + ;
for(int i = ; i <= n; i++)
{
int a,b;
scanf("%d%d", &a, &b);
add(s, i, a);
add(i, t, b);
}
for(int i = ; i <= m; i++)
{
int a,b,w;
scanf("%d%d%d", &a, &b, &w);
add(a, b, w);
add(b, a, w);
}
} bool bfs()
{
memset(vis, , sizeof(vis));
d[s] = ;
queue<int> q;
q.push(s);
vis[s] = true;
while(!q.empty())
{
int x = q.front(); q.pop();
for (int i = ; i < g[x].size(); i++)
{
Edge &e = edge[g[x][i]];
if(e.cap> && !vis[e.to])
{
vis[e.to] = true;
q.push(e.to);
d[e.to] = d[x] + ;
}
}
}
return vis[t];
} int dfs(int u,int f)
{
if(u==t || f==) return f;
for(int &i = cur[u]; i < g[u].size(); i++)
{
Edge &e = edge[g[u][i]];
if(e.cap> && d[e.to] == d[u] + )
{
int d = dfs(e.to, min(f,e.cap));
if(d>)
{
e.cap -= d;
edge[g[u][i]^].cap += d;
return d;
}
}
}
return ;
} int max_flow()
{
int res = ;
while(bfs())
{
memset(cur, , sizeof(cur));
int d;
while(d=dfs(s,INF))
{
res += d;
}
}
return res;
}
int main()
{
debug();
while(scanf("%d%d", &n, &m) != EOF)
{
build();
printf("%d\n", max_flow());
}
return ;
}
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: 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(最小割)
[题目链接] 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——最小割
题目:http://poj.org/problem?id=3469 最小割裸题. 那个限制就是在 i.j 之间连双向边. 根据本题能引出网络流中二元关系的种种. 别忘了写 if ( x==n+1 ) ...
- poj 3469 Dual Core CPU
题目描述:由于越来越多的计算机配置了双核CPU,TinySoft公司的首席技术官员,SetagLilb,决定升级他们的产品-SWODNIW.SWODNIW包含了N个模块,每个模块必须运行在某个CPU中 ...
- 【网络流#8】POJ 3469 Dual Core CPU 最小割【ISAP模板】 - 《挑战程序设计竞赛》例题
[题意]有n个程序,分别在两个内核中运行,程序i在内核A上运行代价为ai,在内核B上运行的代价为bi,现在有程序间数据交换,如果两个程序在同一核上运行,则不产生额外代价,在不同核上运行则产生Cij的额 ...
- poj 3469 Dual Core CPU 最小割
题目链接 好裸的题....... 两个cpu分别作为源点和汇点, 每个cpu向元件连边, 权值为题目所给的两个值, 如果两个元件之间有关系, 就在这两个元件之间连边, 权值为消耗,这里的边应该是双向边 ...
随机推荐
- 【转载】new和malloc的区别
本篇随笔为转载,原贴地址:C++中new和malloc的十点区别. 前言 几个星期前去面试C++研发的实习岗位,面试官问了个问题: new与malloc有什么区别? 这是个老生常谈的问题.当时我回答n ...
- select 一直返回0
select设置超时时间后一直返回零,是因为每次select后监听的fd_set都被重置,解决方法就是每次重新设置
- solr清空全部索引
http://blog.csdn.net/qing419925094/article/details/42142117
- 磁盘阵列(RAID)实例
raid技术分类可以分为基于软件raid技术和基于硬件raid技术 raid又分为raid-0.raid-1.raid-5和raid-10 Raid有”廉价磁盘冗余阵列”的意思,就是利用多块廉价的硬盘 ...
- 深入理解JavaScript系列
转自http://www.cnblogs.com/TomXu/archive/2011/12/15/2288411.html 深入理解JavaScript系列(1):编写高质量JavaScript代码 ...
- java打包成jar,但不打包配置文件
有时候我们做java project的时候,都会打包成jar程序,为了方便部署会加个配置文件conf/pro.properties(conf文件夹与src文件夹同级) 但是不想打包进jar.其实用ec ...
- jquery template模版引擎
jTemplates http://jtemplates.tpython.com/ jquery-template https://github.com/codepb/jquery-template ...
- asp.net(C#)利用QRCode生成二维码(续)-在二维码图片中心加Logo或图像
<%@ WebHandler Language="C#" Class="GetQRCode" %> using System; using Syst ...
- PHP中的特殊符号
<?php 注解符号: // 单行注解 /* */ 多行注解 引号的使用 ' ' 单引号,没有任何意义,不经任何处理直接拿过来; " "双引号,php动态处理然后输出,一般用 ...
- unity3d 孤岛求生基础案例
第二个案例,此案例主要实现了第一人称控制器,把移动从世界坐标系转化到人物平面坐标系,通过碰撞器,触发器,光线透射触发器实现交互.实现UI texture记录收集信息,ui texture是更新内容对应 ...