【hdu 4289】Control
【Link】:http://acm.hdu.edu.cn/showproblem.php?pid=4289
【Description】
给出一个又n个点,m条边组成的无向图。给出两个点s,t。对于图中的每个点,去掉这个点都需要一定的花费。求至少多少花费才能使得s和t之间不连通。
【Solution】
最小割问题.
根据最大流最小割定理;
跑一次最大流即可;
因为是去掉点;
所以,把每个点转换成2个点;
2个点之间建一条边,容量为删掉它的花费.
这两个泛化出来的点,一个点作为原本点的“进点”,另一个作为“出点”,然后和其他点的边,容量都改成INF即可.
这样割就变成割那些泛化出来的点之间的不是INF的边了.
用dicnic算法搞.
【NumberOf WA】
10
【Reviw】
网络在建边的时候,要建双向边.
EK算法有负向边的.
【Code】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x+1)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 200;
const int M = 2e4;
const LL INF = 1e18;
struct abc{
int en,nex;
LL flow;
};
int n,m,s,t,cost[N+10],deep[N*2+20];
int fir[N*2+10],tfir[N*2+10],totm;
abc bian[M*4 + N * 2 + 10];
queue <int> dl;
void add(int x,int y,LL cost){
bian[totm].nex = fir[x];
fir[x] = totm;
bian[totm].en = y,bian[totm].flow = cost;
totm++;
bian[totm].nex = fir[y];
fir[y] = totm;
bian[totm].en = x,bian[totm].flow = 0;
totm++;
}
bool bfs(int s,int t){
dl.push(s);
ms(deep,255);
deep[s] = 0;
while (!dl.empty()){
int x = dl.front();
dl.pop();
for (int temp = fir[x]; temp!= -1 ;temp = bian[temp].nex){
int y = bian[temp].en;
if (deep[y]==-1 && bian[temp].flow){
deep[y] = deep[x] + 1;
dl.push(y);
}
}
}
return deep[t]!=-1;
}
LL dfs(int x,int t,LL limit){
if (x == t) return limit;
if (limit == 0) return 0;
LL cur,f = 0;
for (int temp = tfir[x];temp!=-1;temp = bian[temp].nex){
tfir[x] = temp;
int y = bian[temp].en;
if (deep[y] == deep[x] + 1 && (cur = dfs(y,t,min(limit,(LL)bian[temp].flow))) ){
f += cur;
limit -= cur;
bian[temp].flow -= f;
bian[temp^1].flow += f;
if (!limit) break;
}
}
return f;
}
int main(){
//Open();
//Close();
while (~ri(n)){
ri(m);
ri(s),ri(t);
totm = 0;
rep1(i,1,2*N+5) fir[i] = -1;
rep1(i,1,n) {
ri(cost[i]);
add(2*i-1,2*i,cost[i]);
}
rep1(i,1,m){
int x,y;
ri(x),ri(y);
add(2*x,2*y-1,INF);
add(2*y,2*x-1,INF);
}
s = 2*s-1,t = 2*t;
LL ans = 0;
while ( bfs(s,t) ){
rep1(i,1,2*n) tfir[i] = fir[i];
ans += dfs(s,t,INF);
}
ol(ans);puts("");
}
return 0;
}
【hdu 4289】Control的更多相关文章
- 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题
[HDU 3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...
- 【HDU 5647】DZY Loves Connecting(树DP)
pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...
- -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】
[把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...
- 【HDU 2196】 Computer(树的直径)
[HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...
- 【HDU 2196】 Computer (树形DP)
[HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...
- 【HDU 5145】 NPY and girls(组合+莫队)
pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...
- 【47.63%】【hdu 1532】Drainage Ditches
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s) ...
- 【hdu 1043】Eight
[题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1043 [题意] 会给你很多组数据; 让你输出这组数据到目标状态的具体步骤; [题解] 从12345 ...
- 【HDU 3068】 最长回文
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3068 [算法] Manacher算法求最长回文子串 [代码] #include<bits/s ...
随机推荐
- MySQL 大数据量文本插入
导入几万条数据需要等好几分钟的朋友来围观一下! 百万条数据插入,只在一瞬间.呵呵夸张,夸张!! 不到半分钟是真的! 插入指令: load data infile 'c:/wamp/tmp/Data_O ...
- mysql(for update)悲观锁总结与实践
悲观锁,正如其名,它指的是对数据被外界(包括本系统当前的其他事务,以及来自外部系统的事务处理)修改持保守态度,因此,在整个数据处理过程中,将数据处于锁定状态.悲观锁的实现,往往依靠数据库提供的锁机制( ...
- silverlight wcf mvvm
近期工作比較忙.也没有时间发表新内容,今天有点时间,就顺便写点,说说近期开发的一套系统心得. 我刚去这个公司已经将前端确定要用Silverlight,我不知道为什么要选择这个,或许是为以后转C/S系统 ...
- back_inserter 与 iterator
查看这里: http://www.cplusplus.com/reference/iterator/back_inserter/ 是用来在最后插入的 注意,这个函数,是隐式特化了.
- 移动App架构设计
移动App架构设计 本文主要总结了几种经常使用的架构模式, 基本是层层递进的转载请注名出处 http://blog.csdn.net/uxyheaven, 良好的排版在https://github.c ...
- legend---三、方法集思路
legend---三.方法集思路 一.总结 一句话总结:其实也就是工具包思路,会极大的简化编程,清晰逻辑 1.多if转换成简洁单if怎么实现? 下面这段代码是错的,if的这种写法只适合直接return ...
- Java 开发 2.0: 现实世界中的 Redis
原文地址:http://www.ibm.com/developerworks/cn/java/j-javadev2-22/ 之前,我已在本系列中讨论过 NoSQL 的概念,也介绍了一些与 Java 平 ...
- 对Jscript操作注册表接口的一点不解
作者:朱金灿 来源:http://blog.csdn.net/clever101 要操作注册表需要通过ActiveX控件调用WScript.shell对象,通过该对象的一些方法来操作.Wshshell ...
- gym 100735I
Description standard input/outputStatements You are given three numbers. Is there a way to replace v ...
- 简单STL笔记
想了好久,还是把自己了解的先整理一下吧,毕竟老是忘,这里主要简单介绍三种容器 set,queue,vector,以及栈 stack,队列queue 的简单用法.一.set 在set中,效率比vecto ...