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 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

题意:
在图中,删除点需要相应的花费,求最小的花费,使得s,t不连通。
思路:
最大流=最小割。
一开始忘记了,这个,想了半天费用流。。。
拆带限制点的流量即可。
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime> #define fuck(x) cerr<<#x<<" = "<<x<<endl;
#define debug(a, x) cerr<<#a<<"["<<x<<"] = "<<a[x]<<endl;
#define ls (t<<1)
#define rs ((t<<1)|1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int maxm = ;
const int inf = 0x3f3f3f3f;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-); int Head[maxn],cnt;
struct edge{
int Next,v;
int w;
}e[maxm];
void add_edge(int u,int v,int w){
e[cnt].Next=Head[u];
e[cnt].v=v;
e[cnt].w=w;
Head[u]=cnt++;
} int D_vis[maxn],D_num[maxn];
int source,meeting;
int n,m;
bool bfs()
{
memset(D_vis,,sizeof(D_vis));
for(int i=;i<=*n;i++){//注意要覆盖所有点
D_num[i]=Head[i];
}
D_vis[source]=;
queue<int>q;
q.push(source);
while(!q.empty()){
int u=q.front();
q.pop();
int k=Head[u];
while(k!=-){
if(!D_vis[e[k].v]&&e[k].w){
D_vis[e[k].v]=D_vis[u]+;
q.push(e[k].v);
}
k=e[k].Next;
}
}
return D_vis[meeting];
}
int dfs(int u,int f)
{
if(u==meeting){return f;}
int &k=D_num[u];
while(k!=-){
if(D_vis[e[k].v]==D_vis[u]+&&e[k].w){
int d=dfs(e[k].v,min(f,e[k].w));
if(d>){
e[k].w-=d;
e[k^].w+=d;
return d;
}
}
k=e[k].Next;
}
return ;
}
int Dinic()
{
int ans=;
while(bfs()){
int f;
while((f=dfs(source,inf))>){
ans+=f;
} }
return ans;
} int city1(int x){
return x;
}
int city2(int x){
return x+n;
} int main() {
// ios::sync_with_stdio(false);
// freopen("in.txt", "r", stdin); while (scanf("%d%d",&n,&m)!=EOF){
memset(Head,-,sizeof(Head));
cnt=;
scanf("%d%d",&source,&meeting);
meeting+=n;
for(int i=;i<=n;i++){
int x;
scanf("%d",&x);
add_edge(city1(i),city2(i),x);
add_edge(city2(i),city1(i),);
}for(int i=;i<=m;i++){
int x,y;
scanf("%d%d",&x,&y);
add_edge(city2(x),city1(y),inf);
add_edge(city1(y),city2(x),);
add_edge(city2(y),city1(x),inf);
add_edge(city1(x),city2(y),);
}
printf("%d\n",Dinic());
} return ;
}

HDU - 4289 Control (Dinic)的更多相关文章

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

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

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

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

  3. HDU 4289 Control 最小割

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

  4. hdu 4289 Control 网络流

    题目链接 给出一些点, 每个点有一个权值, 给出一些边, 起点以及终点, 去掉一些点使得起点和终点不连通, 求最小的val. 拆点, 把一个点s拆成s和s', 之间建一条边, 权值为点权. 对于一条边 ...

  5. HDU 4289 Control (最小割 拆点)

    Control Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

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

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

  7. HDU 4289 Control

    最小割 一个点拆成两个 AddEdge(i,i+N,x); 原图中的每条边这样连 AddEdge(u+N,v,INF); AddEdge(v+N,u,INF); S是源点,t+N是汇点.最大流就是答案 ...

  8. hdu 4289 最大流拆点

    大致题意:     给出一个又n个点,m条边组成的无向图.给出两个点s,t.对于图中的每个点,去掉这个点都需要一定的花费.求至少多少花费才能使得s和t之间不连通. 大致思路:     最基础的拆点最大 ...

  9. (网络流 最大流 Dinic || SAP)Control -- hdu --4289

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=4289 http://acm.hust.edu.cn/vjudge/contest/view.action ...

随机推荐

  1. SDUT-3363_驴友计划

    数据结构实验之图论七:驴友计划 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 做为一个资深驴友,小新有一张珍藏的自驾游 ...

  2. 洛谷2591BZOJ2298 problem a题解

    题目连接 bz链接 我们发现,如果一个人有ai个分数比他高的人,有bi个分数比他低的人 那么按照分数排序后,区间[ai+1,n-bi]中的人分数便是相同的 这样就将一个人转化为一个区间 也许有很多人的 ...

  3. 让开发部署提速 8 倍,我参与贡献这款 IDE 插件的全过程

    如何像参与开源那样,去参与一款 IDE 插件的设计? 作为一款 IDE 插件的使用者,我是否能决定下一个版本的功能? 自从产品经理银时小伙和他的开发小哥们在去年12月发布 Cloud Toolkit( ...

  4. 在沙箱中IE不能上网的解决方法

    近期在解决一个问题,在我们的沙箱中IE不能上网 现象:     IE不能上网.输入www.baidu.com 提示:不能查找到DNS.也不能ping 通     其它浏览器上网没有问题(SG浏览器,C ...

  5. laravel中如何实现验证码验证及使用

    开发环境: laravel5.5 php7.1.11 mysql 验证码 是防止恶意破解密码.刷票.论坛灌水.刷页的手段.验证码有 多种类型. 现在我给大家实现如何使用图片验证码,其原理是让用户输入一 ...

  6. laravel 随笔

    laravel5.5 1.laravel 查询数据库默认返回对象,如何改成 返回值为数组 答:在  App\Providers\EventServiceProvider 文件中 第一步: use Il ...

  7. SecureCRT 7.1.1和SecureFx key 亲测可用

    CRT:Name: ygeRCompany: TEAM ZWTSerialNumber: 03-77-119256License Key: ABH2MJ 9YVAC5 Z17QF7 4ZAS7Z AB ...

  8. Jquery常用方法汇总(转)

    https://blog.csdn.net/lucky___star/article/details/87883888

  9. 根据User Agent参数的各个字段Mozilla/5.0/4.0-AppleWebKit/Chrome/Safari/Firefox/Opera/MSIE来确定/判断客户端使用什么浏览器

    下面给你一一解答以及给你介绍: //Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN) AppleWebKit/533.21.1 (KHTML, like ...

  10. 关于XIFF开发IM的一些想法

    因为发现网上XIFF的资料真的不多,何况现在gg又被和谐,查询资料很是不便.我写这篇文章的目的除了跟大家分享一些开发心得,也希望有类似经验的朋友看到文章后有机会多多交流. 之前我没有怎么接触过flas ...