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的基本机制是由系统预留的一块全局 ...
- JAVA字符串格式化-String.format()的使用 (转载)
常规类型的格式化 String类的format()方法用于创建格式化的字符串以及连接多个字符串对象.熟悉C语言的同学应该记得C语言的sprintf()方法,两者有类似之处.format()方法有两种重 ...
- Ios中比较两个日期之间的时间差距
1.比较两个日期之间的时间差距 // 1.日历对象(标识:时区相关的标识) NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIde ...
- 关于Latent Dirichlet Allocation
今天,也没出去,晚上宿舍没有人,自己思考了下人生,毕设还是大事,觉得现在有必要把LDA从前往后彻彻底底的读一遍了,因为现在的感觉就是什么都知道一点皮毛,但是理解的都不深,LDA好像(恩,相当不好)现在 ...
- MVC路由调试工具RouteDebug
环境 MVC3 路由注册 入口简单,在Global.asax文件RegisterRoutes方法中. 当为我们的应用程序注册多个路由后,由于注册不当,得不到预期的结果.为什么会发生这种情况,请求具体走 ...
- where group by联合使用
where group by联合使用 select 列a,聚合函数 from 表名 where 过滤条件 group by 列a having 过滤条件 group by 字句也和where条件语 ...
- Java核心技术II读书笔记(二)
ch2 XML 有两种XML文档结构,DTD和Schema,用解释文档构成规则,这些规则指定了每个元素俺的合法子元素和属性. DTD DTD有多种提供方式,可以像下面这样加到XML中: <?xm ...
- Java Web 乱码
1.mySql编码 2.jdbc编码 http://www.blogjava.net/NicholasEcho/archive/2008/11/03/238310.html ----- 1.HttpG ...
- 看来ms sql server if 中定义个变量出了if 还是可以用的
begin declare @abc int; end print @abc 可以打出1出来
- eclipse插件explorer安装使用
我们知道myeclipse有个open in explorer的按钮.可以方便我们打开任意IDC下的文件或则插件目录 但是eclipse下确没有.因此需要下载下载个eclipse explorer插件 ...