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 ...
随机推荐
- C语言Windows程序开发—CreateWindow函数介绍【第03天】
(一)CreateWindow函数的参数介绍: HWND CreateWindow( LPCTSTR lpClassName, //Windows窗口中预定义的控件结构体,包括:BUTTON(按钮), ...
- HDU1209:Clock
参考:https://blog.csdn.net/libin56842/article/details/8990530 https://blog.csdn.net/u011479875/article ...
- tomcat 异常
Removing obsolete files from server... Could not clean server of obsolete files: null java.lang.Null ...
- 序列化反序列化--Xstream的使用
之前讲了fastjson的使用--将JavaBean与json对象之间互相转换. 该篇文章,教大家使用Xstream来实现XMl与JavaBean的转换. 第一步: 通过maven引入XStream的 ...
- MySQL☞insert value与values
最近公司事情太忙,作为以一挑十的测试,只能苦逼的累死累活的.好不容易临近上线,可以偷个懒写个文章. 简单的说说如何向表中插入数据: 1.向表中所有的列插入数据(插入多行数据): insert int ...
- python 网络篇(网络编程)
一.楔子 你现在已经学会了写python代码,假如你写了两个python文件a.py和b.py,分别去运行,你就会发现,这两个python的文件分别运行的很好.但是如果这两个程序之间想要传递一个数据, ...
- 51单片机实现外部中断0-F
#include< reg51.h> #define uint unsigned int #define uchar unsigned char sfr P0M0 = 0x94; sfr ...
- 爬取妹子图(requests + BeautifulSoup)
刚刚入门爬虫,今天先对于单个图集进行爬取,过几天再进行翻页爬取. 使用requests库和BeautifulSoup库 目标网站:妹子图 今天是对于单个图集的爬取,就选择一个进行爬取,我选择的链接为: ...
- ZooKeeper的伪分布式集群搭建
ZooKeeper集群的一些基本概念 zookeeper集群搭建: zk集群,主从节点,心跳机制(选举模式) 配置数据文件 myid 1/2/3 对应 server.1/2/3 通过 zkCli.sh ...
- ardupilot_gazebo仿真(一)
ardupilot_gazebo仿真 标签(空格分隔): 未分类 ardupilot_gazebo仿真 官网网址 代码更新地址 Ardupilot Gazebo Plugin & Models ...