hdu 4289 Control(最小割 + 拆点)
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
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
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).
See samples for detailed information.
题目大意:
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(最小割 + 拆点)的更多相关文章
- HDU 4289 Control 最小割
Control 题意:有一个犯罪集团要贩卖大规模杀伤武器,从s城运输到t城,现在你是一个特殊部门的长官,可以在城市中布置眼线,但是布施眼线需要花钱,现在问至少要花费多少能使得你及时阻止他们的运输. 题 ...
- hdu-4289.control(最小割 + 拆点)
Control Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- HDU 4289 Control(最大流+拆点,最小割点)
题意: 有一群恐怖分子要从起点st到en城市集合,你要在路程中的城市阻止他们,使得他们全部都被抓到(当然st城市,en城市也可以抓捕).在每一个城市抓捕都有一个花费,你要找到花费最少是多少. 题解: ...
- HDU 4289 Control (网络流,最大流)
HDU 4289 Control (网络流,最大流) Description You, the head of Department of Security, recently received a ...
- HDU 4289 Control (最小割 拆点)
Control Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- HDU4289 Control —— 最小割、最大流 、拆点
题目链接:https://vjudge.net/problem/HDU-4289 Control Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- hdu4289 Control --- 最小割,拆点
给一个无向图.告知敌人的起点和终点.你要在图上某些点安排士兵.使得敌人不管从哪条路走都必须经过士兵. 每一个点安排士兵的花费不同,求最小花费. 分析: 题意可抽象为,求一些点,使得去掉这些点之后,图分 ...
- HDU(2485),最小割最大流
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2485 Destroying the bus stations Time Limit: 40 ...
- HDU 4971 (最小割)
Problem A simple brute force problem (HDU 4971) 题目大意 有n个项目和m个问题,完成每个项目有对应收入,解决每个问题需要对应花费,给出每个项目需解决的问 ...
随机推荐
- 【笨嘴拙舌WINDOWS】剪切板
Windows剪贴板是一种比较简单同时也是开销比较小的IPC(InterProcess Communication,进程间通讯)机制.Windows系统支持剪贴板IPC的基本机制是由系统预留的一块全局 ...
- Linux磁盘占用100%解决方法
/opt分区被web日志堆满了,导致一些服务无法正常运行,于是rm -fr掉这些日志(近11GB),但是服务仍没有恢复正常,用df -hT看,该分区占用还是100%: [root@anjing opt ...
- python执行mysqldump命令
本文简单讲述如何利用python执行一些sql语句,例如执行mysqldump命令,进行数据库备份,备份成sql文件 #!/usr/bin/python#导入os模块import os#导入时间模块i ...
- poj 1465 Multiple(bfs+余数判重)
题意:给出m个数字,要求组合成能够被n整除的最小十进制数. 分析:用到了余数判重,在这里我详细的解释了.其它就没有什么了. #include<cstdio> #include<cma ...
- 20160203.CCPP体系详解(0013天)
程序片段(01):数组.c+02.数组初始化语法.c 内容概要:数组 ///01.数组.c #include <stdio.h> #include <stdlib.h> //0 ...
- 【英语】Bingo口语笔记(75) - 元音辅音的辨读
- log4j配置文件详细解释
web.xml中配置启动log4j的配置 <!-- webAppRootKey进行配置,这里主要是让log能将日志写到对应项目根目录下 --> <!-- 定义以后,在Web Cont ...
- Arduino 使用舵机库时 其它引脚输出怪异 解决方案
使用Servo.h时,不管你在初始化时用的是9还是10脚,都不要把这两个脚作为舵机以外的用途! 例: servo.attach(9); digitalWrite(10,1);//错,不能把第10脚用作 ...
- javascript对象之 selectionStart selectionEnd
<script> function inserttag(){ var text=document.getElementById('con'); text.focus(); var star ...
- openGl从零开始之添加颜色
OpenGL 支持两种颜色模式:一种是 RGBA模式,一种是 颜色索引模式.无论哪种颜色模式,计算机都必须为每一个像素保存一些数据,即通过每一个像素的颜色,来改变整体图形的颜色.不同的是, RGBA ...