Control

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

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
 
Source
这应该是比较裸的一道最小割了,分割两城市,显而易见的最小割啦,拆点就行了...
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. const int maxn = + , maxm = + , inf = 0x3f3f3f3f;
  7. struct Edge {
  8. int to, cap, flow, next;
  9. } edge[maxm << ];
  10.  
  11. int tot, head[maxn << ], que[maxn << ], dep[maxn << ], cur[maxn << ], sta[maxn << ];
  12.  
  13. void init() {
  14. tot = ;
  15. memset(head, -, sizeof head);
  16. }
  17.  
  18. void addedge(int u, int v, int w, int rw = ) {
  19. edge[tot].to = v; edge[tot].cap = w; edge[tot].flow = ;
  20. edge[tot].next = head[u]; head[u] = tot ++;
  21. edge[tot].to = u; edge[tot].cap = rw; edge[tot].flow = ;
  22. edge[tot].next = head[v]; head[v] = tot ++;
  23. }
  24.  
  25. bool bfs(int s, int t, int n) {
  26. int front = , tail = ;
  27. memset(dep, -, sizeof dep[] * (n + ));
  28. dep[s] = ;
  29. que[tail ++] = s;
  30. while(front < tail) {
  31. int u = que[front ++];
  32. for(int i = head[u]; ~i; i = edge[i].next) {
  33. int v = edge[i].to;
  34. if(edge[i].cap > edge[i].flow && dep[v] == -) {
  35. dep[v] = dep[u] + ;
  36. if(v == t) return true;
  37. que[tail ++] = v;
  38. }
  39. }
  40. }
  41. return false;
  42. }
  43.  
  44. int dinic(int s,int t, int n) {
  45. int maxflow = ;
  46. while(bfs(s, t, n)) {
  47. for(int i = ; i <= n; i ++) cur[i] = head[i];
  48. int u = s, tail = ;
  49. while(cur[s] != -) {
  50. if(u == t) {
  51. int tp = inf;
  52. for(int i = tail - ; i >= ; i --)
  53. tp = min(tp, edge[sta[i]].cap - edge[sta[i]].flow);
  54. maxflow += tp;
  55. for(int i = tail - ; i >= ; i --) {
  56. edge[sta[i]].flow += tp;
  57. edge[sta[i] ^ ].flow -= tp;
  58. if(edge[sta[i]].cap - edge[sta[i]].flow == ) tail = i;
  59. }
  60. u = edge[sta[tail] ^ ].to;
  61. }
  62. else if(cur[u] != - && edge[cur[u]].cap > edge[cur[u]].flow && dep[u] + == dep[edge[cur[u]].to]) {
  63. sta[tail ++] = cur[u];
  64. u = edge[cur[u]].to;
  65. }
  66. else {
  67. while(u != s && cur[u] == -)
  68. u = edge[sta[-- tail] ^ ].to;
  69. cur[u] = edge[cur[u]].next;
  70. }
  71. }
  72. }
  73. return maxflow;
  74. }
  75.  
  76. int main() {
  77. int n, m, s, t, u, v, cost;
  78. while(~scanf("%d %d", &n, &m)) {
  79. init();
  80. scanf("%d %d", &s, &t);
  81. for(int i = ; i <= n; i ++) {
  82. scanf("%d", &cost);
  83. addedge(i, n + i, cost);
  84. }
  85. for(int i = ; i <= m; i ++) {
  86. scanf("%d %d", &u, &v);
  87. addedge(u + n, v, inf);
  88. addedge(v + n, u, inf);
  89. }
  90. printf("%d\n", dinic(s, t + n, * n));
  91. }
  92. return ;
  93. }

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

  1. HDU 4289 Control 最小割

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

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

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

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

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

  4. hdu 4289 Control(最小割 + 拆点)

    http://acm.hdu.edu.cn/showproblem.php?pid=4289 Control Time Limit: 2000/1000 MS (Java/Others)    Mem ...

  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. C#基础知识之父子类,实例、静态成员变量,构造函数的执行顺序(经典示例)

    父子类.示例.静态成员变量.构造函数的概念的基础理解完全可以利用下面的示例诠释,非常经典,直接上代码: public class ShowInfo { public ShowInfo(string i ...

  2. java Thread源码分析(二)

    一.sleep的使用 public class ThreadTest { public static void main(String[] args) throws InterruptedExcept ...

  3. 控制DIV内容滚动的方法,实现不用拖滚动条就可以看到最新消息

    三种控制DIV内容滚动的方法: 本人qq群也有许多的技术文档,希望可以为你提供一些帮助(非技术的勿加). QQ群:   281442983 (点击链接加入群:http://jq.qq.com/?_wv ...

  4. node项目实战-用node-koa2-mysql-bootstrap搭建一个前端论坛

    前言 在学习了koa2和express并写了一些demo后,打算自己写一个项目练练手,由于是在校生,没什么好的项目做,即以开发一个前端论坛为目标,功能需求参照一下一些社区拟定,主要有: 登录注册 个人 ...

  5. Flask【第1篇】:Flask介绍

    Flask入门 一.Flask介绍(轻量级的框架,非常快速的就能把程序搭建起来) Flask是一个基于Python开发并且依赖jinja2模板和Werkzeug WSGI服务的一个微型框架,对于Wer ...

  6. axios中put和patch的区别(都是update , put是需要提交整个对象资源,patch是可以修改局部)

    patch方法用来更新局部资源,这句话我们该如何理解? 假设我们有一个UserInfo,里面有userId, userName, userGender等10个字段.可你的编辑功能因为需求,在某个特别的 ...

  7. [洛谷P2886] 牛继电器Cow Relays

    问题描述 For their physical fitness program, N (2 ≤ N ≤ 1,000,000) cows have decided to run a relay race ...

  8. [UVa1057] Routing

    问题描述 As more and more transactions between companies and people are being carried out electronically ...

  9. 【PowerOJ1751&网络流24题】数字梯形问题(费用流)

    题意: 思路: [问题分析] 求图的最大权不相交路径及其变种,用费用最大流解决. [建模方法] 规则(1) 把梯形中每个位置抽象为两个点<i.a>,<i.b>,建立附加源S汇T ...

  10. JMH简介

    JMH是新的microbenchmark(微基准测试)框架(2013年首次发布).与其他众多框架相比它的特色优势在于,它是由Oracle实现JIT的相同人员开发的.特别是我想提一下Aleksey Sh ...