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

  1. 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题

    [HDU  3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...

  2. 【HDU 5647】DZY Loves Connecting(树DP)

    pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...

  3. -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】

    [把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...

  4. 【HDU 2196】 Computer(树的直径)

    [HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...

  5. 【HDU 2196】 Computer (树形DP)

    [HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...

  6. 【HDU 5145】 NPY and girls(组合+莫队)

    pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...

  7. 【47.63%】【hdu 1532】Drainage Ditches

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s) ...

  8. 【hdu 1043】Eight

    [题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1043 [题意] 会给你很多组数据; 让你输出这组数据到目标状态的具体步骤; [题解] 从12345 ...

  9. 【HDU 3068】 最长回文

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3068 [算法] Manacher算法求最长回文子串 [代码] #include<bits/s ...

随机推荐

  1. 巧用MAC地址表

    对于身处网络环境的人来说,不少朋友应该遇到过这种的情况:某一个终端找不到接在了哪一个交换机口上,也不知道数据包怎样走的. ok,那么这时候MAC地址表就作用了,拿下图的实验环境(H3C)来说好了 环境 ...

  2. tab.py

    vim tab.py #!/usr/bin/env python # #Tab import sys import readline import rlcompleter import atexit ...

  3. 20180929 北京大学 人工智能实践:Tensorflow笔记01

    北京大学 人工智能实践:Tensorflow笔记 https://www.bilibili.com/video/av22530538/?p=13 (完)

  4. 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory

    [题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...

  5. 转载-- Qt Creator编译时make: arm-linux-g++: command not found 错误!

    前提是已经配置好交叉编译器,但是qt creator找不到. 解决方法: 修改 /usr/local/Trolltech/QtEmbedded-4.7.0-arm/mkspecs/qws/linux- ...

  6. 虚构造函数与prototype

    注意,构造函数不能是虚的,不然不会生效?(构造函数里面调用虚的函数,也不会生效). 而虚构造函数,指的是通过一个虚函数,来调用clone方法,生成一个新的实例.而这个clone里面,一般调用的是拷贝构 ...

  7. 【Hibernate步步为营】--(一对多映射)之单向关联

    上篇文章讨论了双向关联的一对一映射,用了两个章节,主要是从主键和外键两种关联映射展开具体讨论.双向关联的映射须要在两个映射文件里分别加入相互的相应关系.斌刚在相应的类中加入相应的关联类的属性.这样在一 ...

  8. js如何生成[n,m]的随机数(整理总结)

    js如何生成[n,m]的随机数(整理总结) 一.总结 一句话总结: // max - 期望的最大值 // min - 期望的最小值 parseInt(Math.random()*(max-min+1) ...

  9. POJ 1636 DFS+DP

    思路: 先搜索出来如果选这个点 其它哪些点必须选 跑个背包就好了 //By SiriusRen #include <cstdio> #include <cstring> #in ...

  10. 推荐的JavaScript编码规范

    http://www.qdfuns.com/notes/26812/7825414125719306fa409c709ee7b2a3.html