题目大意:

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的更多相关文章

  1. poj 1273最大流dinic算法模板

    #include<stdio.h> #include<string.h> #define N 300 #define inf 0x7fffffff #include<qu ...

  2. 网络流之最大流Dinic --- poj 1459

    题目链接 Description A power network consists of nodes (power stations, consumers and dispatchers) conne ...

  3. poj 3281 最大流+建图

    很巧妙的思想 转自:http://www.cnblogs.com/kuangbin/archive/2012/08/21/2649850.html 本题能够想到用最大流做,那真的是太绝了.建模的方法很 ...

  4. 网络流之最大流Dinic算法模版

    /* 网络流之最大流Dinic算法模版 */ #include <cstring> #include <cstdio> #include <queue> using ...

  5. poj-1459-最大流dinic+链式前向星-isap+bfs+stack

    title: poj-1459-最大流dinic+链式前向星-isap+bfs+stack date: 2018-11-22 20:57:54 tags: acm 刷题 categories: ACM ...

  6. 网络最大流Dinic

    1.什么是网络最大流 形象的来说,网络最大流其实就是这样一个生活化的问题:现在有一个由许多水管组成的水流系统,每一根管道都有自己的最大通过水流限制(流量),超过这个限制水管会爆(你麻麻就会来找你喝茶q ...

  7. POJ 3469.Dual Core CPU 最大流dinic算法模板

    Dual Core CPU Time Limit: 15000MS   Memory Limit: 131072K Total Submissions: 24830   Accepted: 10756 ...

  8. POJ 1149 PIGS(Dinic最大流)

    PIGS Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20738   Accepted: 9481 Description ...

  9. POJ 3469(Dual Core CPU-最小割)[Template:网络流dinic V2]

    Language: Default Dual Core CPU Time Limit: 15000MS   Memory Limit: 131072K Total Submissions: 19321 ...

随机推荐

  1. Error configuring application listener of class org.springframework.web.context.

    1.java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor 缺少asm-3.3.jar 2.java.lang.NoClassDe ...

  2. sudo 出现unable to resolve host hostname 解决方法

    Linux 环境,我的电脑叫枝桠(机器的hostname), 每次执行sudo 就出现这个警告讯息: sudo: unable to resolve host 枝桠 直接修改 /etc/hosts 的 ...

  3. MES training

    unique identity 1.project name , namespace 2. select XML (not html) 3. view and controller will be i ...

  4. 算法竞赛模板 动态规划之背包DP

    ① 01背包 有n件物品和一个容量为v的背包.第i件物品的价值是c[i],体积是w[i].求解将哪些物品装入背包可使价值总和最大. 这是最基础的背包问题,特点是:每种物品仅有一件,可以选择放或不放. ...

  5. LeetCode Array Easy 53. Maximum Subarray 个人解法 和分治思想的学习

    Description Given an integer array nums, find the contiguous subarray (containing at least one numbe ...

  6. IDEA webapp文件夹不识别解决方案

    使用IDEA 创建moudule 用的是的是maven archertype-quickstart ,自动生成并么有webapp目录,于是我从别的项目中拷贝了一个,发现webapp文件夹图标和普通文件 ...

  7. JNI原理与静态、动态注册

    前言 JNI不仅仅在NDK开发中应用,它更是Android系统中Java与Native交互的桥梁,不理解JNI的话,你就只能停留在Java Framework层.这一个系列我们来一起深入学习JNI. ...

  8. case ...esac判断 function方法 循环loop,while do done,until do done

    就类似于其他语言中的case语句 用法 要点 第一 开始结束  case  esac 正好相反 第二  每段程序段需要用  两个:号结束. 例: } in "hello") ech ...

  9. codeforces 724G - Xor-matic Number of the Graph 线性基+图

    题目传送门 题意:给出衣服无向带权图,问有多少对合法的$<u,v,s>$,要求$u$到$v$存在一条路径(不一定是简单路径)权值异或和等于$s$,并且$u<v$.求所有合法三元组的s ...

  10. MySql为某个表增加rownumber

    在mySql中,假设表名为tblA,则 select @x:=@x+1 as rownumber, a.* from (select @x:=0) b, tblA a 此语句执行后,则每行数据之前都会 ...