nyoj 667 碟战 最小割(最大流)
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=677
题意转化:将点0与所有的有间谍的点相连,则题意变为求点0到点n的最小割,直接套最大流EK算法~
下面代码顶点是从1~n+1
代码入下:
#include "stdio.h"
#include "string.h"
#include "queue"
using namespace std; #define N 205
#define INF 0x3fffffff int start,end;
int route[N],dis[N];
int map[N][N]; int MIN(int x,int y){ return x<y?x:y; } int BFS()
{
int i;
int x,y;
memset(route,-1,sizeof(route));
dis[start] = INF;
queue<int> q;
q.push(start);
while(!q.empty())
{
x = q.front();
q.pop();
for(y=1; y<=end; ++y)
{
if(route[y]==-1 && map[x][y]!=0)
{
route[y] = x;
dis[y] = MIN(dis[x],map[x][y]);
q.push(y);
}
}
}
if(route[end]==-1) return 0;
return dis[end];
} int EK(int n)
{
int x,y;
int ans=0;
int kejia;
while(kejia = BFS())
{
ans += kejia;
y = end;
while(y!=start)
{
x = route[y];
map[x][y] -= kejia;
map[y][x] += kejia;
y = x;
}
}
return ans;
} int main()
{
int T,Case;
int i,k;
int n,m,p;
int x,y;
scanf("%d",&T);
for(Case=1; Case<=T; ++Case)
{
memset(map,0,sizeof(map));
scanf("%d%d%d",&n,&m,&p);
for(i=0; i<p; ++i)
{
scanf("%d",&k);
k++;
map[1][k] = map[k][1] = INF;
}
while(m--)
{
scanf("%d %d",&x,&y);
x++; y++;
map[x][y] = map[y][x] = 1;
}
start = 1; end = n+1;
printf("Case #%d: %d\n",Case,EK(end));
}
}
nyoj 667 碟战 最小割(最大流)的更多相关文章
- hdu4289 最小割最大流 (拆点最大流)
最小割最大流定理:(参考刘汝佳p369)增广路算法结束时,令已标号结点(a[u]>0的结点)集合为S,其他结点集合为T=V-S,则(S,T)是图的s-t最小割. Problem Descript ...
- 【BZOJ-1797】Mincut 最小割 最大流 + Tarjan + 缩点
1797: [Ahoi2009]Mincut 最小割 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1685 Solved: 724[Submit] ...
- BZOJ-1001 狼抓兔子 (最小割-最大流)平面图转对偶图+SPFA
1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec Memory Limit: 162 MB Submit: 14686 Solved: 3513 [Submit][ ...
- hdu1569 方格取数(2) 最大点权独立集=总权和-最小点权覆盖集 (最小点权覆盖集=最小割=最大流)
/** 转自:http://blog.csdn.net/u011498819/article/details/20772147 题目:hdu1569 方格取数(2) 链接:https://vjudge ...
- BZOJ1001:狼抓兔子(最小割最大流+vector模板)
1001: [BeiJing2006]狼抓兔子 Description 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的,而且现在的兔子还比较笨, ...
- HDU1565 方格取数(1) —— 状压DP or 插头DP(轮廓线更新) or 二分图点带权最大独立集(最小割最大流)
题目链接:https://vjudge.net/problem/HDU-1565 方格取数(1) Time Limit: 10000/5000 MS (Java/Others) Memory L ...
- 最小割最大流定理&残量网络的性质
最小割最大流定理的内容: 对于一个网络流图 $G=(V,E)$,其中有源点和汇点,那么下面三个条件是等价的: 流$f$是图$G$的最大流 残量网络$G_f$不存在增广路 对于$G$的某一个割$(S,T ...
- Destroying The Graph 最小点权集--最小割--最大流
Destroying The Graph 构图思路: 1.将所有顶点v拆成两个点, v1,v2 2.源点S与v1连边,容量为 W- 3.v2与汇点连边,容量为 W+ 4.对图中原边( a, b ), ...
- HDU(2485),最小割最大流
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2485 Destroying the bus stations Time Limit: 40 ...
随机推荐
- Use the PDFs below or the HTML contents to the left to install and configure P6 EPPM and its additional components.
Welcome to Your Documentation Use the PDFs below or the HTML contents to the left to install and c ...
- WPF Control Hints - TabControl : 怎么修改整个tab header的margin?
WFP里面TabControl我们可以添加多个TabItem,每个TabItem的Header就是我们常点击的tab标签.但是默认的layout行为里面,这个header是有个2个像素的margin, ...
- Oracle基本操作汇总
--10g 新增的表空间类型:大文件 (Bigfile) 表空间.--10g 数据库在创建的时候,会指定默认的表空间类型.如果不特殊指定的话,默认为 SMALLFILE 类型的表空间.SELECT * ...
- C#调用NPOI组件读取excel表格数据转为datatable写入word表格中并向word中插入图片/文字/书签 获得书签列表
调用word的com组件将400条数据导入word表格中耗时10分钟简直不能忍受,使用NPOI组件耗时4秒钟.但是NPOI中替换书签内容的功能不知道是不支持还是没找到. 辅助类 Excel表格数据与D ...
- Genymotion Shell命令
命令行选项 •-h 输出帮助信息 •-r ip_address 连接到特定Genymotion虚拟设备 •-c "command" 在原生shell环境中执行给定命令而后返回 •- ...
- Python tools for Visual Studio插件介绍
Python tools for Visual Studio是一个免费开源的VisualStudio的插件,支持 VisualStudio 2010,2012与2013.我们想要实现的是: ...
- IIS减少工作线程阻塞的方法
IIS的工作进程(w3wp.exe)只提供了有限的工作线程(Work Thread)来处理请求.如果这些线程都因为要等待长时间运行的任务而阻塞,则运行时会将新来的请求排队,而不是立即执行,Web服务器 ...
- IPC机制--Binder
文章来自 Android技术内幕 系统卷 转:http://www.linuxidc.com/Linux/2011-08/40508.htm 什么是IPC机制以及IPC机制的种类 在Linux中,是以 ...
- Java 进程占用 VIRT 虚拟内存超高的问题研究
1. 现象 最近发现线上机器 java 8 进程的 VIRT 虚拟内存使用达到了 50G+,如下图所示: 2. 不管用的 -Xmx 首先第一想到的当然使用 java 的 -Xmx 去限制堆的使用.但是 ...
- Android WebView 获取网页的标题
final TextView txtTitle = (TextView) findViewById(R.id.txtTitle); final WebView webView = (WebView)f ...