最小割最大流定理:(参考刘汝佳p369)增广路算法结束时,令已标号结点(a[u]>0的结点)集合为S,其他结点集合为T=V-S,则(S,T)是图的s-t最小割。

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

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

思路:最基础的拆点最大流,把每个点拆作两个点i和i0,连接 I——>I0费用为去掉这个点的花费,如果原图中有一条边a和b,则连接a0和b0。(总之这四个点连完之后必须全部在环上)对图求最大流即可。

//这道题跨越了快一个月的时间,终于搞懂了,好开心—2016.9.9 ^_^。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
#define INF 0x7fffffff struct Edge
{
int st,ed;
int c;
int next;
} edge[]; int N,M,St,Ed;
int d[],head[];
int I; void Addedge(int u,int v,int c)
{
edge[I].st=u;
edge[I].ed=v;
edge[I].c=c;
edge[I].next=head[u];
head[u]=I++; edge[I].st=v;
edge[I].ed=u;
edge[I].c=;
edge[I].next=head[v];
head[v]=I++;
} bool bfs()
{
memset(d,-,sizeof(d));
int cur;
queue<int>q;
d[St]=;
q.push(St);
while(!q.empty())
{
cur=q.front();
q.pop();
if(cur==Ed+N) return true;
for(int i=head[cur]; i!=-; i=edge[i].next)
{
if(d[edge[i].ed]==- && edge[i].c>)
{
d[edge[i].ed]=d[cur]+;
q.push(edge[i].ed);
}
}
}
return false;
} int dinic(int n,int flow)
{
if(n==Ed+N) return flow;
int a,mflow=;
for(int i=head[n]; i!=-; i=edge[i].next)
{
if(d[edge[i].ed]==d[n]+ && edge[i].c)
{
a=dinic(edge[i].ed, min(flow-mflow,edge[i].c));
edge[i].c -= a;
edge[i^].c+=a;
mflow+=a;
if(mflow==flow) break;
}
}
if(mflow==) d[n]=-;
return mflow;
} int main()
{
int a,b,x;
while(scanf("%d%d",&N,&M)!=EOF)
{
scanf("%d%d",&St,&Ed);
memset(head,-,sizeof(head));
I=;
for(int i=; i<=N; i++)
{
scanf("%d",&x);
Addedge(i,i+N,x);
}
for(int i=; i<=M; i++)
{
scanf("%d%d",&a,&b);
Addedge(N+a,b,INF);
Addedge(N+b,a,INF);
}
int ans=;
while(bfs())
ans+=dinic(St,INF);
printf("%d\n",ans);
}
return ;
}

对简单的dinic再进一步优化。

hdu4289 最小割最大流 (拆点最大流)的更多相关文章

  1. hdu4289(最小割)

    传送门:Control 题意:有n个城市,有个小偷想从其中一个城市逃到另一个城市,警察想要堵截这个小偷,知道了在每个城市堵截的成本,问如何安排在哪些城市堵截可以使得小偷一定会被抓住,而且成本最低. 分 ...

  2. hdu4289最小割

    最近博客断更了一段时间啊,快期末了,先把这个专题搞完再说 最小割=最大流 拆点方法很重要,刚开始我拆点不对就wa了,然后改进后tle,应该是数组开小了,一改果然是 #include<map> ...

  3. hdu 4289 最小割,分拆点为边

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2609 #include <cstdio> #incl ...

  4. hdu-4289.control(最小割 + 拆点)

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

  5. 最小割最大流定理&残量网络的性质

    最小割最大流定理的内容: 对于一个网络流图 $G=(V,E)$,其中有源点和汇点,那么下面三个条件是等价的: 流$f$是图$G$的最大流 残量网络$G_f$不存在增广路 对于$G$的某一个割$(S,T ...

  6. 最小割&网络流应用

    重要链接 基础部分链接 : 二分图 & 网络流初步 zzz大佬博客链接 : 网络流学习笔记 重点内容:最小割二元关系新解(lyd's ppt) 题目:网络流相关题目 lyd神犇课件链接 : 网 ...

  7. BZOJ 3438: 小M的作物( 最小割 )

    orz出题人云神... 放上官方题解... 转成最小割然后建图跑最大流就行了... ---------------------------------------------------------- ...

  8. 最小割求法&&可行边和必须边

    最小割的可行边与必须边 就是在残量网络上跑tarjan 可行边: 满流并且残量网络上不能存在入点到出点的路径 必须边: 满流并且残量网络上入点能从源点到达,出点能到汇点. 任意一种最小割求法: 跑一边 ...

  9. SPOJ 839 Optimal Marks(最小割的应用)

    https://vjudge.net/problem/SPOJ-OPTM 题意: 给出一个无向图G,每个点 v 以一个有界非负整数 lv 作为标号,每条边e=(u,v)的权w定义为该边的两个端点的标号 ...

随机推荐

  1. Xcode无法启动ios模拟器的问题

    一.问题描述 开发过程需要来回切换ios模拟器调试程序,开始在iPhone 4s下调试,然后切换到iPhone 6s Plus,再切换回iPhone 4s,遇到无法启动ios模拟器.错误提示如下: 二 ...

  2. codeforces 510B. Fox And Two Dots 解题报告

    题目链接:http://codeforces.com/problemset/problem/510/B 题目意思:给出 n 行 m 列只有大写字母组成的字符串.问具有相同字母的能否组成一个环. 很容易 ...

  3. SQL Server 子查询

    这些主要是老师上课讲的一些知识点,自己做了一些整理放在这里~~~ 子查询可以是标量的.多值的或是表值的. 在期待单个值的地方可以使用标量子查询.例如,以下查询返回具有最大员工编号的员工信息: SELE ...

  4. 【XLL 框架库函数】 Excel/Excel12f

    Excel/Excel12f 这两个库函数分别包装了 C API 中的 Excel4 和 Excel12 函数,它们会检查函数没有参数时是否为零,它将表明创建临时的 XLOPER 或 XLOPER12 ...

  5. iOS 没有安装对应客户端,不应显示对应的图标

    现在很多APP为了让用户更加快捷方便注册,都会使用第三方进行登录,例如QQ/微信/淘宝等.但是上线审核被拒,大致会出现以下内容: Additionally, we found that your ap ...

  6. 原始套接字SOCK_RAW

    原始套接字SOCK_RAW 实际上,我们常用的网络编程都是在应用层的报文的收发操作,也就是大多数程序员接触到的流式套接字(SOCK_STREAM)和数据包式套接字(SOCK_DGRAM).而这些数据包 ...

  7. JavaScript基础——使用运算符

    JavaScript运算符允许你改变一个变量的值.你已经熟悉了用于赋值给变量的=运算符.JavaScript提供了几种不同的运算符,它们可以划分为两大类:算数运算符和赋值运算符. 1.算数运算符 你可 ...

  8. Android Stutio -- 编译报错: Error:File path too long on Windows, keep below 240

    原文:http://blog.csdn.net/qq_28195645/article/details/51556975 目录太长,解决办法: 1.将整个project移到更外层的目录,直至没有报错, ...

  9. SQL学习笔记----更改SQL默认的端口号

    1.SQLServer配置管理器----SQLServer网络配置----MSSQLSERVER的协议---TCP/IP(已启用)---IP地址 清空素有的IP,在IPALL下更改默认的端口: 2. ...

  10. Linux(CentOS)常用操作指令(二)

    1.安装wget指令: yum -y install wget 2.安装ifconfig指令: yum install net-tools 3.tar解压文件的使用:  tar -zxvf  aaa. ...