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

最新文章

  1. Angular2学习笔记——NgModule
  2. iOS音乐播放器相关
  3. 搜索引擎Solr系列(二): Solr6.2.1 从MySql中导入数据
  4. salesforce 零基础学习(四十一)Group
  5. LeetCode344:Reverse String@Python
  6. day4----json的简单实用
  7. 基于jsp+servlet图书管理系统之后台用户信息修改操作
  8. 【HDOJ】1063 Exponentiation
  9. python 递归展开嵌套的序列(生成器用法)
  10. APIJSON-以坚持和偏执,回敬傲慢和偏见
  11. 微信小程序view标签以及display:flex的测试
  12. 一个Windows下线程池的实现(C++)
  13. appium滑动操作(向上、向下、向左、向右)
  14. Swift中如何化简标准库中冗长的类实例初始化代码
  15. ibm云时代的转型
  16. Ubuntu 17.10 UTC
  17. pytorch识别CIFAR10:训练ResNet-34(数据增强,准确率提升到92.6%)
  18. Fastjson反序列化漏洞研究
  19. css 如何“画”一个抽奖转盘
  20. C++模板的特化

热门文章

  1. poj2391 最大流+拆点
  2. 直击 KubeCon 2019 现场,阿里云 Hands-on Workshop 亮点回顾
  3. 微信小程序入门到实战(1)-基础知识
  4. qt 自定义窗口显示鼠标划过的轨迹
  5. cPickle对python对象进行序列化,序列化到文件或内存
  6. oracle函数 power(x,y)
  7. 15个非常重要的Apache开源项目汇总
  8. display:flex; justify-content:space-between; 最后一行显示内容无法靠左显示
  9. python不得不知的几个开源项目
  10. 提高github下载速度的方法【100%有效】可达到2MB/s