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(最小割)的更多相关文章

  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 最小割

    Control 题意:有一个犯罪集团要贩卖大规模杀伤武器,从s城运输到t城,现在你是一个特殊部门的长官,可以在城市中布置眼线,但是布施眼线需要花钱,现在问至少要花费多少能使得你及时阻止他们的运输. 题 ...

  5. hdu4289 Control 最大流最小割

    You, the head of Department of Security, recently received a top-secret information that a group of ...

  6. [USACO Section 4.4]追查坏牛奶Pollutant Control (最小割)

    题目链接 Solution 一眼看过去就是最小割,但是要求割边最少的最小的割. 所以要用骚操作... 建边的时候每条边权 \(w = w * (E+1) + 1;\) 那么这样建图跑出来的 \(max ...

  7. 洛谷 P1344 追查坏牛奶Pollutant Control —— 最小割

    题目:https://www.luogu.org/problemnew/show/P1344 就是求最小割: 但是还要边数最小,所以把边权都*1001+1,这样原来流量部分是*1001,最大流一样的不 ...

  8. LG1344 「USACO4.4」Pollutant Control 最小割

    问题描述 LG1344 题解 我太菜了,我一开始竟然没有看出这是个最小割裸题... 两个询问. 第一个询问,直接跑最小割就好了. 第二个询问,建图的时候边权建 \(1\) ,代表割掉这条边需要 \(1 ...

  9. HDU4289(KB11-I 最小割)

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

随机推荐

  1. ruby Encoding

    一. 查看ruby支持的编码 Encoding.name_list 二. 搜索编码 Encoding.find('US-ASCII') #=> US-ASCII,不存在则抛出异常 三. __EN ...

  2. latex01-LaTeX环境的安装与配置

    以Tex Live (跨平台的发行版软件)为例. 1.官网下载iso镜像文件 2.用advanced.bat 安装(管理员权限) 选择要安装的包(主要是去掉多余的语言包) 测试Tex Live 是否正 ...

  3. Makefile中wildcard的介绍

    在Makefile规则中,通配符会被自动展开.但在变量的定义和函数引用时,通配符将失效.这种情况下如果需要通配符有效,就需要使用函数“wildcard”,它的用法是:$(wildcard PATTER ...

  4. C语言实例解析精粹学习笔记——39(简单的文本编辑器)

    实例说明: 编辑一个简单的单行文本编辑器,编辑命令有以下几种:(E.Q.R.I.D) 只有自己在完全空白的情况下编写出来的程序,才是真正自己会的程序,现在所做的,不过是程序的搬运工,把书上的程序搬到网 ...

  5. JavaSE基础复习---2---2018/9/28

    目录: 1.数据类型 2.变量 3.数组 1.数据类型 谈到java的数据类型,必须知道java是强类型语言.首先,每个变量有类型,每个表达式有类型,而且每种类型是严格定义的.其次,所有的数值传递,不 ...

  6. JAVA判断时间是否在时间区间内

    package com.liying.tiger.test; import java.text.ParseException; import java.text.SimpleDateFormat; i ...

  7. 一步一步学Linq to sql(三):增删改

    示例数据库 字段名 字段类型 允许空 字段说明 ID uniqueidentifier 表主键字段 UserName varchar(50) 留言用户名 PostTime datetime 留言时间 ...

  8. 年薪20万Python工程师进阶(7):Python资源大全,让你相见恨晚的Python库

    我是 环境管理 管理 Python 版本和环境的工具 pyenv – 简单的 Python 版本管理工具. Vex – 可以在虚拟环境中执行命令. virtualenv – 创建独立 Python 环 ...

  9. laravel+vue结合使用

        SegmentFault 首页 问答 专栏 讲堂 圈子 发现 搜索 立即登录免费注册 在 SegmentFault,学习技能.解决问题 每个月,我们帮助 1000 万的开发者解决各种各样的技术 ...

  10. MySQL数据库服务器逐渐变慢分析

    第一步 检查系统的状态 1.1 使用sar来检查操作系统是否存在IO问题 #sar -u 2 10 — 即每隔2秒检察一次,共执行20次. [root@CacheMemCache tester]# s ...