hdu4289 Control 最大流最小割
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 最大流最小割的更多相关文章
- HDU4289 Control —— 最小割、最大流 、拆点
题目链接:https://vjudge.net/problem/HDU-4289 Control Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- hdu-4289.control(最小割 + 拆点)
Control Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- hdu4289 Control --- 最小割,拆点
给一个无向图.告知敌人的起点和终点.你要在图上某些点安排士兵.使得敌人不管从哪条路走都必须经过士兵. 每一个点安排士兵的花费不同,求最小花费. 分析: 题意可抽象为,求一些点,使得去掉这些点之后,图分 ...
- HDU-4289-Control(最大流最小割,拆点)
链接: https://vjudge.net/problem/HDU-4289 题意: You, the head of Department of Security, recently receiv ...
- hiho 第116周,最大流最小割定理,求最小割集S,T
小Hi:在上一周的Hiho一下中我们初步讲解了网络流的概念以及常规解法,小Ho你还记得内容么? 小Ho:我记得!网络流就是给定了一张图G=(V,E),以及源点s和汇点t.每一条边e(u,v)具有容量c ...
- hihocoder 网络流二·最大流最小割定理
网络流二·最大流最小割定理 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi:在上一周的Hiho一下中我们初步讲解了网络流的概念以及常规解法,小Ho你还记得内容么? ...
- [HihoCoder1378]网络流二·最大流最小割定理
思路: 根据最大流最小割定理可得最大流与最小割相等,所以可以先跑一遍EdmondsKarp算法.接下来要求的是经过最小割切割后的图中$S$所属的点集.本来的思路是用并查集处理所有前向边构成的残量网络, ...
- HDU 1569 方格取数(2)(最大流最小割の最大权独立集)
Description 给你一个m*n的格子的棋盘,每个格子里面有一个非负数. 从中取出若干个数,使得任意的两个数所在的格子没有公共边,就是说所取数所在的2个格子不能相邻,并且取出的数的和最大. ...
- FZU 1844 Earthquake Damage(最大流最小割)
Problem Description Open Source Tools help earthquake researchers stay a step ahead. Many geological ...
随机推荐
- JNA调用DLL(入门):让你一眼就学会
DLL(Dynamic Link Library)文件,是基于C语言的动态链接库文件,就是一些封装好的方法,打成dll格式包,供别人调用 JNA是一种能够使Java语言使调用DLL的一种技术, 首先, ...
- 每天CSS学习之!important
通过在CSS属性后面跟上!important参数,就会让该属性的优先级变为最高,不管是在css文件,还是内联style中,就属后面跟了!important这个小弟的属性的优先级最高. 让我们来测试一下 ...
- Centos7下cratedb数据导入导出copy to copy from
crate 创建表结构: 查看表: show tables; 创建表结构: create table tablename (k1 type,k2 type,k3 type); (type = int ...
- DevExpress ASP.NET v18.2新功能详解(二)
行业领先的.NET界面控件2018年第二次重大更新——DevExpress v18.2日前正式发布,本站将以连载的形式为大家介绍新版本新功能.本文将介绍了DevExpress ASP.NET Cont ...
- idea没有错误出现红色波浪线怎么去掉?
在有波浪线的代码上Alt+Enter,弹出的菜单中第一项的子菜单选择disable inspection
- byte[]->new String(byte[]) -> getByte()引发的不一致问题
今天接短信接口,短信接口提供了sdk,我们可以直接用sdk发送请求然后发送对应短信. 但是想使用我们平台自定义的httpUtil实现. 然而忙了1天半,才解决这个问题,还是我同事帮忙找出问题并解决的. ...
- 实现html转png
公司要求将一些重要数据全部以图片的形式放在官网上,防止网络爬虫. 之前都是UI作图,人工上传,为了解放生产力,于是我们程序处理. 步骤: 1.html得到与原图一致的图片(交给前端处理) 2.html ...
- 3-D crustal model transfer to cdl format
The downloaded crustal model file, for example, its name is TW-PS-H14.nc The command is ncdump -b c ...
- centos /data目录扩容
/data盘被日志撑死了,必须扩容 有一块现成的100G的/dev/sdb盘,但是mount到了/data/test目录下,而且还有应用程序在上面进行读写操作 1.先查看哪些应用程序 在占用磁盘 #f ...
- mysql增删改查练习
Mysql增删改查sql语句练习 关于数据库的一些操作: 进入mysql 命令行: mysql -uroot –p 查看所有数据库: show databases; 创建数据库: create dat ...