分析

这类问题的一遍描述,把一些对象分成两组,划分有一些代价,问最小代价。一般性的思路是,

把这两组看成是S点和T点,把划分的代价和割边的容量对应起来求最小割。

把S和可模版tem之间到达关系看作是属于核A,对称地,T对应B。模块tem安装在A上代价Ai,就是割断tem和T,连一条tem到T的容量为Ai的边。

相应地,对于Bi,连一条S到tem容量为Bi的边。当ai安装在A上,bi安装在B上,也就是s - ai, bi - t(-表示可到达),这时候如果有额外花费wi

那么ai - bi之间连上容量为wi的边,反过来bi和ai对换一下也是类似的。

输入很大,光是I/O就能优化1s,ISAP会更快。

/*********************************************************
* ------------------ *
* author AbyssalFish *
**********************************************************/
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
using namespace std; const int maxv = 2e4+, maxe = 4e5+maxv*;
int hd[maxv],to[maxe],nx[maxe],ec,cap[maxe];
#define eachEage int i = hd[u]; ~i; i = nx[i]
inline void add(int u,int v, int cp)
{
nx[ec] = hd[u];
to[ec] = v;
cap[ec] = cp;
hd[u] = ec++;
}
inline void Add(int u,int v,int cp)
{
add(u,v,cp); add(v,u,);
}
int lv[maxv], q[maxv];
bool vis[maxv];
int S,T;
bool bfs()
{
memset(vis,,sizeof(bool)*(T+));
int l = , r = ;
lv[q[r++] = S] = ;
vis[S] = true;
while(l<r){
int u = q[l++];
for(eachEage){
int v = to[i];
if(!vis[v] && cap[i]){
lv[q[r++] = v] = lv[u] + ;
vis[v] = true;
}
}
}
return vis[T];
} int cur[maxv]; int aug(int u,int a)
{
if(u == T || !a) return a;
int flow = ,f;
for(int &i = cur[u]; ~i; i = nx[i]){
int v = to[i];
if(lv[v] == lv[u]+ && (f = aug(v, min(a,cap[i])))){
flow += f; a -= f;
cap[i] -= f; cap[i^] += f;
if(!a) break;
}
}
return flow;
} int maxFlow()
{
int flow = ;
while(bfs()){
memcpy(cur,hd,sizeof(int)*(T+));
flow += aug(S,<<);
}
return flow;
} inline int read()
{
int ret; char c; while(c = getchar(),c<''||c>'');
ret = c-'';
while(c = getchar(),c>=''&&c<='') ret = ret* + c-'';
return ret;
} //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
int n, m;
while(~scanf("%d%d",&n,&m)){
S = ; T = n+;
memset(hd,0xff,sizeof(int)*(T+)); ec = ;
for(int i = ; i <= n; i++){
Add(i,T,read());
Add(S,i,read());
}
for(int i = ; i < m; i++){
int a = read(),b = read(),w = read();
add(a,b,w); add(b,a,w);
}
printf("%d\n",maxFlow());
} return ;
}

POJ 3469 Dual Core CPU(最小割模型的建立)的更多相关文章

  1. poj 3469 Dual Core CPU——最小割

    题目:http://poj.org/problem?id=3469 最小割裸题. 那个限制就是在 i.j 之间连双向边. 根据本题能引出网络流中二元关系的种种. 别忘了写 if ( x==n+1 ) ...

  2. POJ 3469 Dual Core CPU (最小割建模)

    题意 现在有n个任务,两个机器A和B,每个任务要么在A上完成,要么在B上完成,而且知道每个任务在A和B机器上完成所需要的费用.然后再给m行,每行 a,b,w三个数字.表示如果a任务和b任务不在同一个机 ...

  3. 【网络流#8】POJ 3469 Dual Core CPU 最小割【ISAP模板】 - 《挑战程序设计竞赛》例题

    [题意]有n个程序,分别在两个内核中运行,程序i在内核A上运行代价为ai,在内核B上运行的代价为bi,现在有程序间数据交换,如果两个程序在同一核上运行,则不产生额外代价,在不同核上运行则产生Cij的额 ...

  4. poj 3469 Dual Core CPU 最小割

    题目链接 好裸的题....... 两个cpu分别作为源点和汇点, 每个cpu向元件连边, 权值为题目所给的两个值, 如果两个元件之间有关系, 就在这两个元件之间连边, 权值为消耗,这里的边应该是双向边 ...

  5. poj 3469 Dual Core CPU【求最小割容量】

    Dual Core CPU Time Limit: 15000MS   Memory Limit: 131072K Total Submissions: 21453   Accepted: 9297 ...

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

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

  7. POJ 3469 Dual Core CPU Dual Core CPU

    Time Limit: 15000MS   Memory Limit: 131072K Total Submissions: 23780   Accepted: 10338 Case Time Lim ...

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

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

  9. POJ3469 Dual Core CPU(最小割)

    题意:给你n个模块,每个模块在A核花费为ai,在B核跑花费为bi,然后由m个任务(ai,bi,wi),表示如果ai,bi不在同一个核上跑,额外的花费为wi,求最小的花费. 一开始想的时候以为是费用流, ...

随机推荐

  1. CentOS6.5内核升级FATAL: Module scsi_wait_scan not found

    系统为CentOS6.5的虚拟机内核升级至版本4.6.0-1,重启后,报以下错误: Module scsi_wait_scan not found. 无法进入系统. 问题描述详见:Known Issu ...

  2. [CentOS7] gzip, bzip2, xz 压缩与解压缩

    声明:本文主要总结自:鸟哥的Linux私房菜-第八章.檔案與檔案系統的壓縮,打包與備份,如有侵权,请通知博主 gzip命令: 选项参数: -c :将压缩后的数据显示到屏幕上,可以用于重定向: -d : ...

  3. ios各个型号设备屏幕分辨率总结

    https://blog.csdn.net/amyloverice/article/details/79389357     iPhone: iPhone 1G 320x480 iPhone 3G 3 ...

  4. 51nod1118(递推)

    题目链接: https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1118 题意: 中文题诶~ 思路: 因为机器人只能往下或者右 ...

  5. 51nod1021(区间dp)

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1021 题意:中文题诶- 思路:区间dp 我们用num[i]存 ...

  6. MySQL常用配置和性能压力测试:MySQL系列之十五

    一.MySQL常用配置 以下所有配置参数以32G内存的服务器为基 1.打开独立的表空间 innodb_file_per_table = 1 2.MySQL服务所允许的同时会话数的上限,默认为151,经 ...

  7. SQL 日期函数转换

    1.转换函数 与date操作关系最大的就是两个转换函数:to_date(),to_char() to_date() 作用将字符类型按一定格式转化为日期类型: 具体用法:to_date('2004-11 ...

  8. 原生JS轮播-各种效果的极简实现

    寒假持续摸鱼中~此为老早以前博客的重写,当时还是分开写的,这里汇总重写,正好复习一遍~ 春招我来了! 所有有意思的,一股脑先扔进收藏,然后再也不看哈哈,真是糟糕. 今日事,今日毕,说起来容易. 当时竟 ...

  9. spring学习(四)spring的jdbcTemplate(增删改查封装)

    Spring的jdbcTemplate操作 1.Spring框架一站式框架 (1)针对javaee三层,每一层都有解决技术 (2)到dao 层,使用 jdbcTemplate 2.Spring对不同的 ...

  10. LeetCode 260 Single Number III 数组中除了两个数外,其他的数都出现了两次,找出这两个只出现一次的数

    Given an array of numbers nums, in which exactly two elements appear only once and all the other ele ...