POJ 3469 /// 最大流Dinic
题目大意:
N个模块 在核A上执行花费a[i] 在核B上执行花费b[i]
有M个模块组合(d1,d2) 若d1模块与d2模块在不同核上执行需多花费w[i]
求执行所有模块所需的最小花费
挑战P237
将问题转化为最小割问题 求得的最小割就是最小花费
那么记在核A上执行的模块集合为S 核B上执行的模块集合为T 建立源点s 汇点t
某模块在A上执行花费a[i] 则建一条该模块到t容量为a[i]的边
某模块在B上执行花费b[i] 则建一条s到该模块容量为b[i]的边
d1模块与d2模块在不同核上执行需多花费w[i] 则建一条d1与d2间容量为w[i]的无向边
最后求s-t最小割 只要求s到t的最大流就行
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=2e4+;
int n,m,s,t;
struct NODE { int v,w,r; };
vector <NODE> E[N];
void addE(int u,int v,int w) {
E[u].push_back((NODE){v,w,E[v].size()});
E[v].push_back((NODE){u,w,E[u].size()-});
}
/**Dinic*/
int lev[N], cur[N];
void bfs(int s) {
queue <int> q;
memset(lev,-,sizeof(lev));
lev[s]=; q.push(s);
while(!q.empty()) {
int u=q.front(); q.pop();
for(int i=;i<E[u].size();i++) {
NODE e=E[u][i];
if(e.w> && lev[e.v]<) {
lev[e.v]=lev[u]+;
q.push(e.v);
}
}
}
}
// 广搜一遍把可走的点分层保存在lev[]中
int dfs(int s,int t,int f) {
if(s==t) return f;
// 取地址才能修改到cur[]
for(int& i=cur[s];i<E[s].size();i++) {
NODE& e=E[s][i];
if(e.w> && lev[s]<lev[e.v]) {
int d=dfs(e.v,t,min(f,e.w));
if(d>) {
e.w-=d; E[e.v][e.r].w+=d;
return d;
}
}
}
return ;
}
// 深搜找增广路
int maxFlow(int s,int t) {
int flow=;
while() {
bfs(s);
if(lev[t]<) return flow;
memset(cur,,sizeof(cur));
while() {
int f=dfs(s,t,INF);
if(f==) break;
flow+=f;
}
}
}
/***/ int main()
{
while(~scanf("%d%d",&n,&m)) {
s=n, t=s+;
for(int i=;i<=t;i++) E[i].clear();
for(int i=;i<n;i++) {
int a,b; scanf("%d%d",&a,&b);
addE(i,t,a); addE(s,i,b);
}
for(int i=;i<m;i++) {
int a,b,w; scanf("%d%d%d",&a,&b,&w);
addE(a-,b-,w); addE(b-,a-,w);
}
printf("%d\n",maxFlow(s,t));
} return ;
}
POJ 3469 /// 最大流Dinic的更多相关文章
- poj 1273最大流dinic算法模板
#include<stdio.h> #include<string.h> #define N 300 #define inf 0x7fffffff #include<qu ...
- 网络流之最大流Dinic --- poj 1459
题目链接 Description A power network consists of nodes (power stations, consumers and dispatchers) conne ...
- poj 3281 最大流+建图
很巧妙的思想 转自:http://www.cnblogs.com/kuangbin/archive/2012/08/21/2649850.html 本题能够想到用最大流做,那真的是太绝了.建模的方法很 ...
- 网络流之最大流Dinic算法模版
/* 网络流之最大流Dinic算法模版 */ #include <cstring> #include <cstdio> #include <queue> using ...
- poj-1459-最大流dinic+链式前向星-isap+bfs+stack
title: poj-1459-最大流dinic+链式前向星-isap+bfs+stack date: 2018-11-22 20:57:54 tags: acm 刷题 categories: ACM ...
- 网络最大流Dinic
1.什么是网络最大流 形象的来说,网络最大流其实就是这样一个生活化的问题:现在有一个由许多水管组成的水流系统,每一根管道都有自己的最大通过水流限制(流量),超过这个限制水管会爆(你麻麻就会来找你喝茶q ...
- POJ 3469.Dual Core CPU 最大流dinic算法模板
Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 24830 Accepted: 10756 ...
- POJ 1149 PIGS(Dinic最大流)
PIGS Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20738 Accepted: 9481 Description ...
- POJ 3469(Dual Core CPU-最小割)[Template:网络流dinic V2]
Language: Default Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 19321 ...
随机推荐
- nmon 定时任务 监控资源
nmon命令: # ./nmon –f -s 30 –c 100 说明:-f 以文件的形式输出,默认输出是机器名+日期.nmon的格式,也可以用-F指定输出的文件名,例如: # ./nmon_x8 ...
- Linux NIO 系列(04-1) select
目录 一.select 机制的优势 二.select API 介绍与使用 2.1 select 2.2 fd_set 集合操作 2.3 select 使用范例 三.深入理解 select 模型: 四. ...
- bzoj2989 数列
突然翻到一道他们正在做的题....好像是cdq分治??? 以后写写呗.... 然后二进制啥的照样操作一波....感觉很资瓷的样子.... 就这样分组操作两边这道题咯?
- 域名访问和ip访问区别
域名访问和ip访问区别 ip访问对应某一台确定的服务器: 域名访问相当于在ip访问的基础上,做了一个反向代理的中间功能.例如:百度,很多人会同时使用,如果使用的是同一台服务器的话,服务器估计会扛不住, ...
- 2018-2-13-git-cannot-lock-ref
title author date CreateTime categories git cannot lock ref lindexi 2018-2-13 17:23:3 +0800 2018-2-1 ...
- Vmware虚拟机中安装ubuntu18 live server+Vmware Tools(用来共享本地文件夹)
一.安装Ubuntu见链接 https://ywnz.com/linuxaz/3696.html 二.安装Vmware Tools 参考:https://blog.csdn.net/a12340123 ...
- AtomicInteger 、Synchronized 和 volatile 之间的区别?
AtomicInteger:无锁的线程安全整数??? Synchronized:同步 volatile:挥发性??? 参考文档:
- STM32三种BOOT模式介绍
一.三种BOOT模式介绍 所谓启动,一般来说就是指我们下好程序后,重启芯片时,SYSCLK的第4个上升沿,BOOT引脚的值将被锁存.用户可以通过设置BOOT1和BOOT0引脚的状态,来选择在复位后的启 ...
- vuex之module的使用
一.module的作用 由于使用单一状态树,应用的所有状态会集中到一个比较大的对象.当应用变得非常复杂时,store 对象就有可能变得相当臃肿. 为了解决以上问题,Vuex 允许我们将 store 分 ...
- hdu 3450 后缀数组
题目大意: 求多个字符串的最长公共子串 基本思路: 参加我的博客hdu2774 代码如下: #include<cstdio> #include<cstring> using n ...