http://acm.hdu.edu.cn/showproblem.php?pid=4289

Control

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2247    Accepted Submission(s): 940

Problem 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
 
详细请参考:

题目大意:

N个点,每个点都有各自的cost, 然后M 无向条边

要求割去S点到D路线中的点,使之无法从S到D ,而且要求消耗的cost和最小.

这是一道网络流的题. 算的是最小割. 根据最大流最小割定理. 可以直接算最大流;

但是这题的的流量限制是在点上的.所以要我们来拆点.

我这题是把i 点的  点首和点尾 分别设为 i 和 i+n;  显然 最后会得到2*n个点

如图:

将点1拆分成两部分分别为点首1和点尾1+n,然后把点首到点尾的流量限制设成 题目要求的cost; ,点1---->(1+n)的花费即为封锁城市1的代价

而点与点之间(两座城市之间)的边,要设成正无穷大, 因为边不消耗cost;

然后从S的点首S 跑到 D的点尾 D+n  就可以计算出最小割了.

#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
#define N 510
#define INF 0x3f3f3f3f
using namespace std; struct Edge
{
int u, v, flow, next;
} edge[N * N]; int layer[N], head[N], cnt; void Init()
{
memset(head, -, sizeof(head));
cnt = ;
} void AddEdge(int u, int v, int flow)
{
edge[cnt].u = u;
edge[cnt].v = v;
edge[cnt].flow = flow;
edge[cnt].next = head[u];
head[u] = cnt++; swap(u, v); edge[cnt].u = u;
edge[cnt].v = v;
edge[cnt].flow = ;
edge[cnt].next = head[u];
head[u] = cnt++; } bool BFS(int Start, int End)
{
queue<int>Q;
memset(layer, -, sizeof(layer));
Q.push(Start);
layer[Start] = ;
while(!Q.empty())
{
int u = Q.front();
Q.pop();
if(u == End)
return true;
for(int i = head[u] ; i != - ; i = edge[i].next)
{
int v = edge[i].v;
if(layer[v] == - && edge[i].flow > )
{
layer[v] = layer[u] + ;
Q.push(v);
}
}
}
return false;
} int DFS(int u, int Maxflow, int End)
{
if(u == End)
return Maxflow;
int uflow = ;
for(int i = head[u] ; i != - ; i = edge[i].next)
{
int v = edge[i].v;
if(layer[v] == layer[u] + && edge[i].flow > )
{
int flow = min(edge[i].flow, Maxflow - uflow);
flow = DFS(v, flow, End);
edge[i].flow -= flow;
edge[i^].flow += flow; uflow += flow;
if(uflow == Maxflow)
break;
}
}
if(uflow == )
layer[u] = ;
return uflow;
} int Dinic(int Start, int End)
{
int Maxflow = ;
while(BFS(Start, End))
Maxflow += DFS(Start, INF, End);
return Maxflow;
} int main()
{
int m, n, s, t;
while(~scanf("%d%d", &m, &n))
{
Init();
scanf("%d%d", &s, &t);
int u, v, flow;
for(int i = ; i <= m ; i++)
{
scanf("%d", &flow);
AddEdge(i, i + m, flow);
}
while(n--)
{
scanf("%d%d", &u, &v);
AddEdge(u + m, v, INF);
AddEdge(v + m, u, INF);
}
printf("%d\n", Dinic(s, t + m));
}
return ;
}

hdu 4289 Control(最小割 + 拆点)的更多相关文章

  1. HDU 4289 Control 最小割

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

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

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

  3. HDU 4289 Control(最大流+拆点,最小割点)

    题意: 有一群恐怖分子要从起点st到en城市集合,你要在路程中的城市阻止他们,使得他们全部都被抓到(当然st城市,en城市也可以抓捕).在每一个城市抓捕都有一个花费,你要找到花费最少是多少. 题解: ...

  4. HDU 4289 Control (网络流,最大流)

    HDU 4289 Control (网络流,最大流) Description You, the head of Department of Security, recently received a ...

  5. HDU 4289 Control (最小割 拆点)

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

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

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

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

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

  8. HDU(2485),最小割最大流

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2485 Destroying the bus stations Time Limit: 40 ...

  9. HDU 4971 (最小割)

    Problem A simple brute force problem (HDU 4971) 题目大意 有n个项目和m个问题,完成每个项目有对应收入,解决每个问题需要对应花费,给出每个项目需解决的问 ...

随机推荐

  1. hdfs工作原理

    一.NameNode和DataNode (1)NameNode NameNode的作用是管理文件目录结构,是管理数据节点的.NameNode维护两套数据:一套是文件目录与数据块之间的关系,另一套是数据 ...

  2. 阿里云linux服务器安装Phalcon-----"phalcon Volt directory can't be written" "gcc: internal compiler error: Killed (program cc1)"

    这里特别蛋疼的一件事是官方英文文档和中文文档命令参数略有不同 中文文档: //通用平台下安装指定的软件包: sudo yum install git gcc make pcre-devel php-d ...

  3. [asp.net] 通过JS实现对treeview控件的复选框单选控制。

    前端JS代码: //识别不同的浏览器 function getTargetElement(evt) { var elem if (evt.target) { elem = (evt.target.no ...

  4. yii2 html下拉框

    下拉框 带默认值 <?php $form=ActiveForm::begin(); echo $form->field($model,'uname', ['inputOptions'=&g ...

  5. 【基础数学】质数,约数,分解质因数,GCD,LCM

    1.质数: 质数(prime number)又称素数,有无限个.一个大于1的自然数,除了1和它本身外,不能整除以其他自然数(质数),换句话说就是该数除了1和它本身以外不再有其他的因数. 2.约数: 如 ...

  6. 基于HTTP的直播点播HLS

             HLS(HTTP Live Streaming) 是Apple在2009年发布的,可以通过普通的web服务器进行分发的新型流媒体协议.苹果官方对于视频直播服务提出了 HLS 解决方案 ...

  7. suse下设置IP的两种方法

    /Files/yzhxhwt/DB_51aspx.rar 第一种SUSE Linux IP设置方法ifconfig eth0 192.168.1.22 netmask 255.255.255.0 up ...

  8. svn log 不显示日志的问题

    在你配好了Xcode里的SourceControl之后提交代码回复代码都很方便,可是为什么在Xcode上提交的log,在svn下面显示不出来! 解决办法是:在命令行下,先 svn update 一下, ...

  9. zabbix (2.0.6) 历史记录处乱码

    1.首先备份数据库 mysqldump -uroot -p123456 zabbix > zabbix.sql 2.设置字符 sed -i 's/latin1/utf8/g' zabbix.sq ...

  10. Dubbo原理解析-注册中心之Zookeeper协议注册中心

    下面我们来看下开源dubbo推荐的业界成熟的zookeeper做为注册中心, zookeeper是hadoop的一个子项目是分布式系统的可靠协调者,他提供了配置维护,名字服务,分布式同步等服务.对于z ...