【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 ...
随机推荐
- [NOIP2015提高组]子串
题目:洛谷P2679.Vijos P1982.codevs4560.UOJ#149. 题目大意:有长度为n的A串和长度为m的B串.现在要从A串中取出k个互不重叠的子串,使它们按顺序相连后得到B串.问有 ...
- Python安装selenium启动浏览器
1:在Python运行火狐或谷歌的浏览器是需要下载相对应的驱动 例如:你想在Python中使用代码命令打开firefox的网页 如果没有安装驱动,直接运行的话会出下面的错误 所以我们要安装相对应的浏览 ...
- Myeclipse学习总结(4)——Eclipse常用开发插件
(1) AmaterasUML 介绍:Eclipse的UML插件,支持UML活动图,class图,sequence图,usecase图等:支持与Java class/interf ...
- HDU 4406 GPA
GPA Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 440664 ...
- webpack02
consumer-index.html <!DOCTYPE html> <html lang="en"> <head> <meta cha ...
- Redis之创建
redis配置文件信息 public sealed class RedisConfigInfo { /// <summary> /// 可写的Redis链接地址 /// format:ip ...
- HDU 1005 Number Sequence(矩阵)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- Go 编码问题的解决方案
1.首先需要mahonia 这个包 go get github.com/axgle/mahonia 然后新建一个 func src 字符串 srcCode 字符串当前编码 tagCode 要转换的编码 ...
- Java:JDBC操作
内容:供程序员调用的接口与类,集成在java.sql和javax.sql包中,如:DriverManager类Connection接口Statement接口ResultSet接口 1.Class.fo ...
- Mark Sweep GC
目录 标记清除算法 标记阶段 深度优先于广度优先 清除阶段 分配 First-fit.Best-fit.Worst-fit三种分配策略 合并 优点 实现简单 与保守式GC算法兼容 缺点 碎片化 分配速 ...