poj3469 Dual Core CPU --- 最小割
来源:互联网 发布:淘宝上怎么买ig包 编辑:程序博客网 时间:2024/06/11 01:15
一个CPU有两个核,要把n个模块放在其中一个核上,给出放在不同核上的花费。
另给出m对模块,若不放在同一模块则会产生额外花费。求最小花费。
对于每一个模块可以选择核1,核2,和相连的模块。
据此建边,核1为源点,核2为汇点,相连的模块之间建双向边,边权均为花费。求最小割即可。
#include <iostream>#include <cstring>#include <string>#include <cstdio>#include <cmath>#include <algorithm>#include <vector>#include <queue>#include <map>#define inf 0x3f3f3f3f#define eps 1e-6#define ll __int64const int maxn=20010;using namespace std;struct node{ int from,to,cap,flow;};struct dinic{ int n,m,s,t; vector<node> e; vector<int> g[maxn]; bool vis[maxn]; int d[maxn]; int cur[maxn]; void init(int n) { e.clear(); for(int i=0;i<=n+2;i++) g[i].clear(); } void addedge(int a,int b,int c,int d) { e.push_back((node){a,b,c,0}); e.push_back((node){b,a,d,0}); m=e.size(); g[a].push_back(m-2); g[b].push_back(m-1); } bool bfs() { memset(vis,0,sizeof vis); queue<int> q; q.push(s); d[s]=0; vis[s]=1; while(!q.empty()) { int x=q.front();q.pop(); for(int i=0;i<g[x].size();i++) { node& ee=e[g[x][i]]; if(!vis[ee.to]&&ee.cap>ee.flow) { vis[ee.to]=1; d[ee.to]=d[x]+1; q.push(ee.to); } } } return vis[t]; } int dfs(int x,int a) { if(x==t||a==0) return a; int flow=0,f; for(int& i=cur[x];i<g[x].size();i++) { node& ee=e[g[x][i]]; if(d[x]+1==d[ee.to]&&(f=dfs(ee.to,min(a,ee.cap-ee.flow)))>0) { ee.flow+=f; e[g[x][i]^1].flow-=f; flow+=f; a-=f; if(a==0) break; } } return flow; } int maxflow(int s,int t) { this->s=s; this->t=t; int flow=0; while(bfs()) { memset(cur,0,sizeof cur); flow+=dfs(s,inf); } return flow; }};dinic solve;int main(){ int i,a,b,cc,m,n,s,t; while(~scanf("%d%d",&n,&m)) { s=0,t=n+1; solve.init(n); for(i=1;i<=n;i++) { scanf("%d%d",&a,&b); solve.addedge(s,i,a,0); solve.addedge(i,t,b,0); } while(m--) { scanf("%d%d%d",&a,&b,&cc); solve.addedge(a,b,cc,cc); } printf("%d\n",solve.maxflow(s,t)); } return 0;}
0 0
- poj3469 Dual Core CPU --- 最小割
- poj3469 Dual Core CPU-最小花费-最大流最小割
- POJ3469 Dual Core CPU(最大流最小割定理)
- 最大流-最小割定理&poj3469 Dual Core CPU
- POJ3469 Dual Core CPU 【最大流最小割】
- POJ3469 Dual Core CPU 最小割求解最小费用划分集合
- poj3469 - Dual Core CPU
- POJ3469 Dual Core CPU
- POJ3469-Dual Core CPU
- poj3469 Dual Core CPU
- POJ3469 Dual Core CPU
- POJ3469:Dual Core CPU
- (POJ3469)Dual Core CPU 网络流最小割,Dinic模板应用
- poj3469 Dual Core CPU(最大点权独立集+最小割+理解)
- POJ3469: Dual Core CPU 题解
- POJ 3469 Dual Core CPU //最小割
- POJ 3469 Dual Core CPU(最小割)
- poj 3469 Dual Core CPU 最小割
- UVa 11795 - Mega Man's Mission(集合DP 状态压缩)
- tyvj begin 闰秒 wa了2个小时竟然 【水题】
- 对于架构师的一点理解(来自网友讨论)
- 单向链表(五) 按值查找节点,返回一个链表
- 中水处理设备:一体化日常中水回用设备工艺说明
- poj3469 Dual Core CPU --- 最小割
- 线性栈
- B. Sort the Array
- iOS 工作笔记(一)
- C++第十六天 类
- 程序猿个人发展(公司群分享)
- 山东理工OJ【2054】双向链表(两种方法)
- poj 2318 TOYS & poj 2398 Toy Storage (叉积)
- 反渗透设备:电镀厂中水回用反渗透设备概述