题目链接

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

AC

  • 题目要求截住所有的劫匪,所以求一个最小割,使整个图不连通即可
  • 拆点建图(因为双向边)
    1. 将题目给的边,拆开建边,流量为inf
    2. 将每个点拆开建边,流量为花费
#include <iostream>
#include <stdio.h>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#define N 405
#include <cstring>
#define ll long long
#define P pair<int, int>
#define mk make_pair
using namespace std;
struct ac{int v, c, pre;
}edge[20001 * 4];
int head[N], dis[N], curedge[N], cnt;
int inf = 0x3f3f3f3f;
int n, m;
void addedge(int u, int v, int c) {edge[cnt].v = v;edge[cnt].c = c;edge[cnt].pre = head[u];head[u] = cnt++;swap(u, v);edge[cnt].v = v;edge[cnt].c = 0;edge[cnt].pre = head[u];head[u] = cnt++;
}
bool bfs(int s, int e) {queue<int> que;que.push(s);memset(dis, 0, sizeof(dis));dis[s] = 1;while (!que.empty()) {int t = que.front();que.pop();for (int i = head[t]; i != -1; i = edge[i].pre) {if (dis[edge[i].v] || edge[i].c == 0)   continue;dis[edge[i].v] = dis[t] + 1;que.push(edge[i].v);} }return dis[e] != 0;
}
int dfs(int s, int e, int flow) {if (s == e) return flow;for (int &i = curedge[s]; i != -1; i = edge[i].pre) {if (dis[edge[i].v] == dis[s] + 1 && edge[i].c) {int d = dfs(edge[i].v, e, min(flow, edge[i].c));if (d > 0) {edge[i].c -= d;edge[i ^1].c += d;return d; }}}return 0;
}
int solve(int s, int e) {int sum = 0;while (bfs(s, e)) {for (int i = 0; i <= n * 2; ++i) {curedge[i] = head[i];}int d;while (d = dfs(s, e, inf)) {sum += d;}}return sum;
}int main() {
#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);
#endifwhile (scanf("%d%d", &n, &m) != EOF) {cnt = 0;memset(head, -1, sizeof(head));int s, e;scanf("%d%d", &s, &e);// 自己到自己,流量为花费 for (int i = 1; i <= n; ++i) {int t; scanf("%d", &t);addedge(i, i + n, t);}// 建边 for (int i = 0; i < m; ++i) {int l, r;scanf("%d%d", &l, &r);addedge(l + n, r, inf);addedge(r + n, l, inf);}int ans = solve(s, e + n);printf("%d\n", ans);}return 0;
}

HDU Problem - 4289 Control(最大流)相关推荐

  1. hdu 2871 Memory Control(线段树)

    题目链接:hdu 2871 Memory Control 题目大意:模拟一个内存分配机制. Reset:重置,释放全部空间 New x:申请内存为x的空间,输出左地址 Free x:释放地址x所在的内 ...

  2. HDU - 4289 Control(最小割-最大流)

    题目链接:点击查看 题目大意:给出一张n个点m条边的无向图,一些恐怖分子要从点st到点ed去安装炸弹,为了阻止他们这样做,必须在某些点布置警察,只要恐怖分子路过警察所在的点就会被逮捕,在某个点布置警察 ...

  3. hdu 4289 Control

    http://acm.hdu.edu.cn/showproblem.php?pid=4289 唉 本来对网络流的题目就不是很擅长 而且最近也没去碰这方面的题 结果这次有两个用最大流的  而且都是拆点的 ...

  4. HDU Problem - 1533 Going Home(费用流板子题)

    题目链接 Problem Description On a grid map there are n little men and n houses. In each unit time, every ...

  5. HDU Problem - 4280 Island Transport(最大流)

    题目链接 Problem Description In the vast waters far far away, there are many islands. People are living ...

  6. HDU Problem - 3338 Kakuro Extension (最大流,建图)

    题目链接 Problem Description If you solved problem like this, forget it.Because you need to use a comple ...

  7. HDU Problem - 2732 Leapin' Lizards(最大流,拆点建边)

    题目链接 Problem Description Your platoon of wandering lizards has entered a strange room in the labyrin ...

  8. HDU Problem - 4292 Food(最大流, 建边)

    题目链接 Problem Description You, a part-time dining service worker in your college's dining hall, are n ...

  9. 【最小割】HDU 4289 Control

    把一个点拆成两个点 这两点的权值为点的值 #include <stdio.h> #include <string.h> #include <stdlib.h> #i ...

最新文章

  1. iframe标签快速使用
  2. 近期必读的5篇AI顶会CVPR 2020 GNN (图神经网络) 相关论文
  3. public private protected
  4. mac下webstorm 安装
  5. “黑天鹅”,正在改变 AI 落地医疗领域的加速度
  6. (17)VHDL实现编码器
  7. Eclipse中Maven WEB工程tomcat调试
  8. BGP华为、思科选路规则
  9. android开发之自定义AutoCompleteTextView
  10. Android Wi-Fi 2.4G及5G信道一览表
  11. 基于@Aspect实现AOP的两种方式
  12. 【百度编辑器】修改上传图片缩略图大小
  13. 为什么普通人做量化交易会亏钱?
  14. 小新pro13睡眠后无法唤醒_小新air12、air13、air13pro睡眠后无法唤醒的调试方法
  15. 计算机高级 论文怎么考,干货丨如何在一个月内通过高级软考证
  16. 更改Colab的CUDA以及cudnn
  17. HeaFirst设计模式-单件模式[单例模式](Singleton Pattern)
  18. kafka监控api,手撕面试官
  19. 2万买新能源汽车只是开始 聚划算将推出汽车每满3万减6千
  20. 东北师范计算机应用基础20秋在线作业1,21秋21春20秋-计算机应用基础20春在线作业1...

热门文章

  1. CentOS使用virt-what知道虚拟机的虚拟化技术
  2. Ubuntu12下安装redis(多图版)+ Jedis连接Redis
  3. 成为编程高手的二十二条军规
  4. 计算机Java程序设计标准讲义
  5. 汇编排序知识之冒泡排序
  6. Swift之深入解析异步函数async/await的使用与运行机制
  7. iOS之单例模式的写法
  8. Python创建单例模式的5种方法
  9. 中国大学MOOC 人工智能导论第一章测试
  10. BASIC-13 数列排序