HDU-4289 Control(最大流最小割+拆点)

题目链接:HDU-4289 Control

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.

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 10 7.
  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个结点M条边的图,每个点都有各自的点权,其中有起点S和终点T,现要删除部分点使得S和T不连通,求删除的最小点权和。



分析:

很容易想到求最小割,但是最小割求的是删除的最小边权,那么这里就要用到拆点的技巧。
详见:https://www.cnblogs.com/tweetuzki/p/10422496.html#一总述

注意该题为双向边,所以拆点方法如下(u’ = u+n)

该题中对于一个点u,需要拆为 u -> u+n 和 u+n -> u,其中边权即为点权

而对于边u - v,则需要拆为 u+n -> v 和 v+n -> u,其中边权为INF

此外因为起点和终点也拆成了边,所以 源点s=S汇点 t = T+n

此外,求最小割时反向边容量一般不会为0(而是等于正向边),但在这里,因为是将点拆分,且在拆分时就是构建的双向边,所以这里还是需要定反向边容量为0。



以下代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<map>
#include<algorithm>
#define LL long long
using namespace std;
const int INF=
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值