Control

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2247    Accepted Submission(s): 940

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
 
Source
 
 
 

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

大致思路:
    最基础的拆点最大流,把每个点拆作两个点 i 和 i' 连接i->i'费用为去掉这个点的花费,如果原图中有一条边a->b则连接a'->b。对这个图求出最大流即可。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue> using namespace std; const int VM=;
const int EM=;
const int INF=0x3f3f3f3f; struct Edge{
int to,nxt;
int cap;
}edge[EM]; int n,m,src,des,cnt,head[VM];
int dep[VM]; void addedge(int cu,int cv,int cw){
edge[cnt].to=cv; edge[cnt].cap=cw; edge[cnt].nxt=head[cu];
head[cu]=cnt++;
edge[cnt].to=cu; edge[cnt].cap=; edge[cnt].nxt=head[cv];
head[cv]=cnt++;
} int BFS(){
queue<int> q;
while(!q.empty())
q.pop();
memset(dep,-,sizeof(dep));
dep[src]=;
q.push(src);
while(!q.empty()){
int u=q.front();
q.pop();
for(int i=head[u];i!=-;i=edge[i].nxt){
int v=edge[i].to;
if(edge[i].cap> && dep[v]==-){
dep[v]=dep[u]+;
q.push(v);
}
}
}
return dep[des]!=-;
} int DFS(int u,int minx){
if(u==des)
return minx;
int tmp;
for(int i=head[u];i!=-;i=edge[i].nxt){
int v=edge[i].to;
if(edge[i].cap> && dep[v]==dep[u]+ && (tmp=DFS(v,min(minx,edge[i].cap)))){
edge[i].cap-=tmp;
edge[i^].cap+=tmp;
return tmp;
}
}
dep[u]=-;
return ;
} int Dinic(){
int ans=,tmp;
while(BFS()){
while(){
tmp=DFS(src,INF);
if(tmp==)
break;
ans+=tmp;
}
}
return ans;
} int main(){
int s,t;
while(~scanf("%d%d",&n,&m)){
cnt=;
memset(head,-,sizeof(head));
scanf("%d%d",&s,&t);
src=, des=*n+;
addedge(src,s,INF);
addedge(n+t,des,INF);
int u,v,w;
for(int i=;i<=n;i++){
scanf("%d",&w);
addedge(i,n+i,w);
addedge(n+i,i,w);
}
for(int i=;i<=m;i++){
scanf("%d%d",&u,&v);
addedge(n+u,v,INF); //注意这里的建边,src--->s--->u(某条边)---->n+u(拆分u点后的另一点)---->v---->n+v(拆分v点后的另一点)---->u-----
addedge(n+v,u,INF); //所以,addedge(n+u,v,INF);仔细想想,这样才能保证 u 和 v 使连接着的
}
printf("%d\n",Dinic());
}
return ;
}

hdu 4289 网络流拆点,类似最小割(可做模板)邻接矩阵实现的更多相关文章

  1. HDU 5889 Barricade(最短路+最小割水题)

    Barricade Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  2. HDU - 3035 War(对偶图求最小割+最短路)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3035 题意 给个图,求把s和t分开的最小割. 分析 实际顶点和边非常多,不能用最大流来求解.这道题要用 ...

  3. HDU - 3002 King of Destruction(最小割)

    http://acm.hdu.edu.cn/showproblem.php?pid=3002   最小割模板 #include<iostream> #include<cmath> ...

  4. HDU 5889 Barricade(最短路+最小割)

    http://acm.hdu.edu.cn/showproblem.php?pid=5889 题意: 给出一个图,帝国将军位于1处,敌军位于n处,敌军会选择最短路到达1点.现在帝国将军要在路径上放置障 ...

  5. HDU 3691 Nubulsa Expo(全局最小割Stoer-Wagner算法)

    Problem Description You may not hear about Nubulsa, an island country on the Pacific Ocean. Nubulsa ...

  6. 【网络流#8】POJ 3469 Dual Core CPU 最小割【ISAP模板】 - 《挑战程序设计竞赛》例题

    [题意]有n个程序,分别在两个内核中运行,程序i在内核A上运行代价为ai,在内核B上运行的代价为bi,现在有程序间数据交换,如果两个程序在同一核上运行,则不产生额外代价,在不同核上运行则产生Cij的额 ...

  7. HDU 1569 方格取数(2) (最小割)

    方格取数(2) Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  8. 【HDU 6126】Give out candies 最小割

    题意 有$n​$个小朋友,给每个人分$1~m​$个糖果,有k个限制 限制形如$(x,y,z)​$ 表示第$x​$个人分到的糖数减去第$y​$个人分到的糖数不大于$z​$,给第$i​$个人$j​$颗糖获 ...

  9. hdu 6214 Smallest Minimum Cut(最小割的最少边数)

    题目大意是给一张网络,网络可能存在不同边集的最小割,求出拥有最少边集的最小割,最少的边是多少条? 思路:题目很好理解,就是找一个边集最少的最小割,一个方法是在建图的时候把边的容量处理成C *(E+1 ...

随机推荐

  1. 在一个css文件中引入其他css文件

    @import "./main.css";@import "./color-dark.css";@import "./reset.css";

  2. Spark的基本概念及工作原理

    Spark作业的基本概念 -Application:用户自定义的Spark程序,用户提交后,Spark为App分配资源将程序转换并执行. -Driver Program:运行Application的m ...

  3. python_41_with语句

    #为了避免打开文件后忘记关闭,可以通过管理上下文,即:with open('log','r') as f: # 如此方式,当with代码块执行完毕时,内部会自动关闭并释放文件资源. with open ...

  4. sqlldr将txt导入oracle数据库

    注意事项: 1.userid 和 control关键字不要缺少: 2.注意数据库格式:test/test@数据库IP:1521/Oracle8,最后一个是tnsnames中的service_name, ...

  5. @TransactionConfiguration过时与替代写法

    在使用了Spring的项目中做单元测试时,以前的标准写法是这样的: 但是在高版本的Spring框架中(Spring4.2以后),@TransactionConfiguration已经标注为过时的注解, ...

  6. java设计模式——建造者模式

    一. 定义与类型 定义:将一个复杂对象的构建与它的表示分离,使用同样的构建过程可以创建不同的表示 用户只需制定需要建造的类型就可以得到它们,建造过程以及细节不需要知道 类型:创建型 建造者模式与工厂模 ...

  7. vmware:使用.zip文件在vmware中安装操作系统

    问题描述: 之前在vmware中安装系统时,全部都是加载的.iso文件来实现.后面同事给了一个zip包,解压后是".vmdk"等一系列具体的文件.一时间不知道怎么安装系统了,搜网页 ...

  8. head与body(新手向)

    网页文档包含了页头(head)与主体(body) 页头 -是对该网页文档进行描绘的主体信息. -至少含有title与meta. meta描述网页的特征,比如字符编码,平时广泛用的utf-8.且meta ...

  9. 1042: [HAOI2008]硬币购物

    Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3209  Solved: 2001[Submit][Status][Discuss] Descript ...

  10. 【PHP】判断变量是否为控

    1. isset功能:判断变量是否被初始化 说明:它并不会判断变量是否为空,并且可以用来判断数组中元素是否被定义过注意:当使用isset来判断数组元素是否被初始化过时,它的效率比array_key_e ...