HDU4289:Control(最小割)
Control
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5023 Accepted Submission(s): 2067
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4289
Description:
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
Input:
There are several test cases.
The first line of a single test case contains two integer N and M ( 2 <= N <= 200; 1 <= M <= 20000), the number of cities and the number of highways. Cities are numbered from 1 to N.
The second line contains two integer S,D ( 1 <= S,D <= N), the number of the source and the number of the destination.
The following N lines contains costs. Of these lines the ith one contains exactly one integer, the cost of locating SA in the ith city to put it under observation. You may assume that the cost is positive and not exceeding 107.
The followingM lines tells you about highway network. Each of these lines contains two integers A and B, indicating a bidirectional highway between A and B.
Please process until EOF (End Of File).
Output:
For each test case you should output exactly one line, containing one integer, the sum of cost of your selected set.
See samples for detailed information.
Sample Input:
5 6 5 3 5 2 3 4 12 1 5 5 4 2 3 2 4 4 3 2 1
Sample Output:
3
题意:
给出起点和终点城市,每个城市都有一定的权值,有一群坏人要从起点到终点,现在要在一些城市上布置警察拦截这些坏人,问最少花费。
题解:
由于点有权值,我们考虑拆点;同时这题是双向边。
如果我们像以往那样反向边容量也为c,则有误。
我们这样考虑插边:插入的反向边容量还是0,只是这样来构造双向边:u'->v , v'->u。其中u'为出度点,u为入度点。
最后跑个最大流就行了。最大流等于最小割
代码如下:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#define INF 99999999
using namespace std;
typedef long long ll;
const int N = ,M = 1e5;
int head[N],d[N];
int tot,n,m,s,t;
struct Edge{
int v,next,c;
}e[M];
void adde(int u,int v,int c){
e[tot].v=v;e[tot].next=head[u];e[tot].c=c;head[u]=tot++;
e[tot].v=u;e[tot].next=head[v];e[tot].c=;head[v]=tot++;
}
bool bfs(int S,int T){
memset(d,,sizeof(d));d[S]=;
queue <int > q;q.push(S);
while(!q.empty()){
int u=q.front();q.pop();
for(int i=head[u];i!=-;i=e[i].next){
int v=e[i].v;
if(!d[v] && e[i].c>){
d[v]=d[u]+;
q.push(v);
}
}
}
return d[t]!=;
}
int dfs(int u,int a){
int flow=,f;
if(u==t || a==) return a;
for(int i=head[u];i!=-;i=e[i].next){
int v=e[i].v;
if(d[v]!=d[u]+) continue ;
f=dfs(v,min(a,e[i].c));
if(f>){
e[i].c-=f;
e[i^].c+=f;
flow+=f;
a-=f;
if(a==) break;
}
}
if(!flow) d[u]=-;
return flow;
}
int Dinic(){
int max_flow=;
while(bfs(s,t))
max_flow+=dfs(s,INF);
return max_flow;
}
int main(){
while(scanf("%d%d",&n,&m)!=EOF){
memset(head,-,sizeof(head));tot=;
scanf("%d%d",&s,&t);
t+=;
for(int i=,c;i<=n;i++){
scanf("%d",&c);
adde(i,i+,c);
}
for(int i=,u,v;i<=m;i++){
scanf("%d%d",&u,&v);
adde(u+,v,INF);
adde(v+,u,INF);
}
printf("%d\n",Dinic());
}
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 最小割
Control 题意:有一个犯罪集团要贩卖大规模杀伤武器,从s城运输到t城,现在你是一个特殊部门的长官,可以在城市中布置眼线,但是布施眼线需要花钱,现在问至少要花费多少能使得你及时阻止他们的运输. 题 ...
- hdu4289 Control 最大流最小割
You, the head of Department of Security, recently received a top-secret information that a group of ...
- [USACO Section 4.4]追查坏牛奶Pollutant Control (最小割)
题目链接 Solution 一眼看过去就是最小割,但是要求割边最少的最小的割. 所以要用骚操作... 建边的时候每条边权 \(w = w * (E+1) + 1;\) 那么这样建图跑出来的 \(max ...
- 洛谷 P1344 追查坏牛奶Pollutant Control —— 最小割
题目:https://www.luogu.org/problemnew/show/P1344 就是求最小割: 但是还要边数最小,所以把边权都*1001+1,这样原来流量部分是*1001,最大流一样的不 ...
- LG1344 「USACO4.4」Pollutant Control 最小割
问题描述 LG1344 题解 我太菜了,我一开始竟然没有看出这是个最小割裸题... 两个询问. 第一个询问,直接跑最小割就好了. 第二个询问,建图的时候边权建 \(1\) ,代表割掉这条边需要 \(1 ...
- HDU4289(KB11-I 最小割)
Control Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
随机推荐
- 04 mysql 基础三 (进阶)
mysql 基础三 阶段一 mysql 单表查询 1.查询所有记录 select * from department; select * from student; select * from ...
- Spyder在windows下常用快捷键
块注释/反块注释:Ctrl+4/5 行注释/反行注释:Ctrl+1 代码提示:Tab 复制一行:Ctrl+Alt+↓/↑ 删除一行:Ctrl+D 运行:F5 全屏:F11 撤销:Ctrl+Z 反撤销: ...
- 【转】Django添加静态文件设置
STATIC_URL = '/statics/'STATIC_ROOT= os.path.join(BASE_DIR, 'statics')STATICFILES_DIRS = ( os.path.j ...
- 浅谈 kubernetes service 那些事 (下篇)
欢迎访问网易云社区,了解更多网易技术产品运营经验. 五.K8s 1.8 新特性--ipvs ipvs与iptables的性能差异 随着服务的数量增长,IPTables 规则则会成倍增长,这样带来的问题 ...
- 使用Visual Studio 2017构建.Net Core的Docker镜像
1 Docker 镜像优化 微软在为开发人员生成 Docker 镜像时,提供以下三种主要方案: 用于开发 .NET Core 应用的 镜像 用于构建生成 .NET Core 应用的 镜像 用于运行 ...
- DO NOT BELIEVE HIS LIES 游戏随笔
这游戏是我大学的一个基友推荐的,好吧,感觉被他坑了··· 解谜游戏~慢慢来玩玩··· 恩,就是下面红色圈圈画起来的这个家伙. #1 第一关 好吧,界面上也没啥可聊的,上面写了一行字,THE FIRST ...
- python,批量生成指定格式的审核数据(传输参数格式为数组时)
#思路#获取list长度(例如列表有20条数据,则生成20条数据),生成数组长度为list元素的数据,完成对列表20条数据的批量审核def createBatchData(self,str_in,li ...
- Selenium搭配TestNG
用Maven来构建TestNG依赖: <dependency> <groupId>org.testng</groupId> <artifactId>te ...
- mysql修改外部访问权限
mysql>use mysql; mysql>update user set host =’%’ where user=’root’ mysql>select host,user f ...
- 实用的placeholder插件,兼容IE下的placeholder,jquery插件
placeholder在IE下无法兼容 ,下面的插件很好的处理了这个问题,拿去不谢 /* * jQuery placeholder, fix for IE6,7,8,9 * @website itmy ...