You, the head of Department of Security, recently received a top-secret information that a group of terrorists is planning to transport some WMD 1 from one city (the source) to another one (the destination). You know their date, source and destination, and they are using the highway network.
  The highway network consists of bidirectional highways, connecting two distinct city. A vehicle can only enter/exit the highway network at cities only.
  You may locate some SA (special agents) in some selected cities, so that when the terrorists enter a city under observation (that is, SA is in this city), they would be caught immediately.
  It is possible to locate SA in all cities, but since controlling a city with SA may cost your department a certain amount of money, which might vary from city to city, and your budget might not be able to bear the full cost of controlling all cities, you must identify a set of cities, that:
  * all traffic of the terrorists must pass at least one city of the set.
  * sum of cost of controlling all cities in the set is minimal.
  You may assume that it is always possible to get from source of the terrorists to their destination.
------------------------------------------------------------
1 Weapon of Mass Destruction

题意:有一些城市,城市之间有一些边,有通缉犯要从一个城市到另一个城市,为了抓捕通缉犯,你需要调遣兵力守在若干城市,以保证通缉犯无论从哪里走都一定会经过有你的部下看守的城市,问最少需要部署多少个城市。

最小割性质的裸题,就是使原点和汇点不连通的最小割的大小,建边直接跑网络流,最大流=最小割。

 #include<stdio.h>
#include<string.h>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
const int maxm=;
const int INF=0x7fffffff; struct edge{
int from,to,f;
edge(int a,int b,int c):from(a),to(b),f(c){}
}; struct dinic{
int s,t,m;
vector<edge>e;
vector<int>g[maxm];
bool vis[maxm];
int cur[maxm],d[maxm]; void init(int n){
for(int i=;i<=n;i++)g[i].clear();
e.clear();
} void add(int a,int b,int c){
e.push_back(edge(a,b,c));
e.push_back(edge(b,a,));
m=e.size();
g[a].push_back(m-);
g[b].push_back(m-);
} bool bfs(){
memset(vis,,sizeof(vis));
queue<int>q;
q.push(s);
vis[s]=;
d[s]=;
while(!q.empty()){
int u=q.front();
q.pop();
for(int i=;i<g[u].size();i++){
edge tmp=e[g[u][i]];
if(!vis[tmp.to]&&tmp.f>){
d[tmp.to]=d[u]+;
vis[tmp.to]=;
q.push(tmp.to);
}
}
}
return vis[t];
} int dfs(int x,int a){
if(x==t||a==)return a;
int flow=,f;
for(int& i=cur[x];i<g[x].size();i++){
edge& tmp=e[g[x][i]];
if(d[tmp.to]==d[x]+&&tmp.f>){
f=dfs(tmp.to,min(a,tmp.f));
tmp.f-=f;
e[g[x][i]^].f+=f;
flow+=f;
a-=f;
if(a==)break;
}
}
if(flow==)d[x]=-;
return flow;
} int mf(int s,int t){
this->s=s;
this->t=t;
int flow=;
while(bfs()){
memset(cur,,sizeof(cur));
flow+=dfs(s,INF);
}
return flow;
}
}; int main(){
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
dinic d;
d.init(*n+);
int a,b;
scanf("%d%d",&a,&b);
d.add(,a,INF);
d.add(b+n,*n+,INF);
int i,j;
for(i=;i<=n;i++){
scanf("%d",&a);
d.add(i,i+n,a);
}
for(i=;i<=m;i++){
scanf("%d%d",&a,&b);
d.add(a+n,b,INF);
d.add(b+n,a,INF);
}
printf("%d\n",d.mf(,*n+));
}
return ;
}

hdu4289 Control 最大流最小割的更多相关文章

  1. HDU4289 Control —— 最小割、最大流 、拆点

    题目链接:https://vjudge.net/problem/HDU-4289 Control Time Limit: 2000/1000 MS (Java/Others)    Memory Li ...

  2. hdu-4289.control(最小割 + 拆点)

    Control Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  3. hdu4289 Control --- 最小割,拆点

    给一个无向图.告知敌人的起点和终点.你要在图上某些点安排士兵.使得敌人不管从哪条路走都必须经过士兵. 每一个点安排士兵的花费不同,求最小花费. 分析: 题意可抽象为,求一些点,使得去掉这些点之后,图分 ...

  4. HDU-4289-Control(最大流最小割,拆点)

    链接: https://vjudge.net/problem/HDU-4289 题意: You, the head of Department of Security, recently receiv ...

  5. hiho 第116周,最大流最小割定理,求最小割集S,T

    小Hi:在上一周的Hiho一下中我们初步讲解了网络流的概念以及常规解法,小Ho你还记得内容么? 小Ho:我记得!网络流就是给定了一张图G=(V,E),以及源点s和汇点t.每一条边e(u,v)具有容量c ...

  6. hihocoder 网络流二·最大流最小割定理

    网络流二·最大流最小割定理 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi:在上一周的Hiho一下中我们初步讲解了网络流的概念以及常规解法,小Ho你还记得内容么? ...

  7. [HihoCoder1378]网络流二·最大流最小割定理

    思路: 根据最大流最小割定理可得最大流与最小割相等,所以可以先跑一遍EdmondsKarp算法.接下来要求的是经过最小割切割后的图中$S$所属的点集.本来的思路是用并查集处理所有前向边构成的残量网络, ...

  8. HDU 1569 方格取数(2)(最大流最小割の最大权独立集)

    Description 给你一个m*n的格子的棋盘,每个格子里面有一个非负数. 从中取出若干个数,使得任意的两个数所在的格子没有公共边,就是说所取数所在的2个格子不能相邻,并且取出的数的和最大.   ...

  9. FZU 1844 Earthquake Damage(最大流最小割)

    Problem Description Open Source Tools help earthquake researchers stay a step ahead. Many geological ...

随机推荐

  1. day17-json格式转换

    Json简介:Json,全名 JavaScript Object Notation,是一种轻量级的数据交换格式.Json最广泛的应用是作为AJAX中web服务器和客户端的通讯的数据格式.现在也常用于h ...

  2. day10-高阶函数

    高阶函数 高阶函数:就是把函数当成参数传递的一种函数,例如: def add(x,y,f): return f(x)+f(y) print(add(-8,11,abs)) 结果: 19 解释: 调用a ...

  3. javascript es6系列教程 - 不定参数与展开运算符(...)

    三个点(...)在es6中,有两个含义: 用在形参中, 表示传递给他的参数集合, 类似于arguments, 叫不定参数. 语法格式:  在形参面前加三个点( ... ) 用在数组前面,可以把数组的值 ...

  4. 关于执行findbugs,checkstyle,jacoco插件检测代码,GitHook的脚本编写

    Git钩子的作用: (pre-commit ) 在用户执行 git commit -m "xxx" 命令之前,先执行pre-commit文件中的脚本命令 在pre-commit文件 ...

  5. 1014 2018 使用FLAG counter

    AmazingCounters.com 不能用了,服务器访问不了了,之前的博客浏览量也看不到了,1014号换了个新的--FLAG counter,就是博客右边那个.

  6. 数字签名-MD5

    MD5是信息摘要的意思,报文产生摘要是唯一的(1:1),而且是单向的(通过摘要反推不出源报文) java中的java.security.MessageDigest类,参考MessageDigest的功 ...

  7. FindResource () RT_HTML 为什么总是出错呢 ?

    #include <windows.h> #include <commdlg.h> #include <ole2.h> BOOL GetHtmlResource(L ...

  8. leetcode57:插入区间

    给出一个无重叠的 ,按照区间起始端点排序的区间列表. 在列表中插入一个新的区间,你需要确保列表中的区间仍然有序且不重叠(如果有必要的话,可以合并区间). 示例 1: 输入: intervals = [ ...

  9. [Spring]初识Spring-Spring的基础使用-如何通过Bean来实例化?

    Spring框架的基础使用 XML配置信息,Bean的不同实例化方式,注入 实例化 XML文件中的参数设置 1.通过构造器进行实例化(重点,常用方式) <bean name="aCls ...

  10. 框架:Spring IoC

    Spring篇 第二章.Spring IoC简介 一.基本概念 控制反转是一个比较抽象的概念,是Spring框架的核心,用来消减计算机程序的耦合问题. 依赖注入是IoC的另外一种说法,只是从不同的角度 ...