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. 仔细看看Javascript中的逻辑与(&&)和逻辑或(||)

    学过Java和C的人,都知道逻辑与(&&)和逻辑或(||),他们都是短路运算符,也就是说,对于&&来说,只要左边的操作数是false,它就不会再去判断右边的操作数是tr ...

  2. @RequestBody对象为空,异常Required request body is missing错误解决

    1.异常 org.springframework.http.converter.HttpMessageNotReadableException: Required request body is mi ...

  3. 2018-2-13-win10-uwp-获取按钮鼠标左键按下

    title author date CreateTime categories win10 uwp 获取按钮鼠标左键按下 lindexi 2018-2-13 17:23:3 +0800 2018-2- ...

  4. 【C++】STL,vector容器操作

    C++内置的数组支持容器的机制,但是它不支持容器抽象的语义.要解决此问题我们自己实现这样的类.在标准C++中,用容器向量(vector)实现.容器向量也是一个类模板.标准库vector类型使用需要的头 ...

  5. LeetCode86 Partition List

    题目: Given a linked list and a value x, partition it such that all nodes less than x come before node ...

  6. KiCad Mark 点名称

    KiCad Mark 点名称 Mark 点的用处是给 IC 等高密度的元件在贴片时定位参考.

  7. 【批量添加】-拼接sql字符串 标签: 批量添加 2015-12-13 17:49 2070人阅读 评论(33)

    现在做的一个项目需要用到批量添加,但是封装的底层没有这个方法,所以自食其力,自己来写.我们用的是拼接sql字符串的方法来实现功能. 具体实现流程:首先将需要的数据存储到实体的list中,然后将这个li ...

  8. 04使用harbor配置私仓

    安装harbor之前,需要安装好Python,Docker,DockerCompose.Python需要2.7以上的版本,Docker需要1.10以上的版本:Docker Compose 需要1.6. ...

  9. Flask学习之六 个人资料和头像

    英文博客地址:http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-vi-profile-page-and-avatars ...

  10. Django ORM------Mysql

    ORM操作 select * from tb where id > 1 #对应关系 models.tb.objects.filter(id__gt=1) models.tb.objects.fi ...