poj1815Friendship(最小割求割边)
题意为去掉多少个顶点使图不连通,求顶点连通度问题。拆点,构造图,对于<u,v>可以变成<u2,v1> <v2,u1>容量为无穷,<u1,u2>容量为1.那么求出来的最大流(即最小割)就为所需要删除的顶点个数,需要字典序输出,从小到大枚举顶点,如果不加入当前点,最小割变小了的话 ,说明这个点是肯定要删除的。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f
const int N = ;
#define M 160015
struct node
{
int u,v,next;
int w;
} edge[M<<];
int head[N],t,vis[N],pp[N],dis[N];
int o[N];
int st,en;
int x[N][N],f[N];
void init()
{
t=;
memset(head,-,sizeof(head));
}
void add(int u,int v,int w)
{
edge[t].u = u;
edge[t].v = v;
edge[t].w = w;
edge[t].next = head[u];
head[u] = t++;
edge[t].u = v;
edge[t].v = u;
edge[t].w = ;
edge[t].next = head[v];
head[v] = t++;
}
int bfs()
{
int i,u;
int w;
memset(dis,-,sizeof(dis));
queue<int>q;
q.push(st);
dis[st] = ;
while(!q.empty())
{
u = q.front();
q.pop();
for(i = head[u] ; i != - ; i = edge[i].next)
{
int v = edge[i].v;
w = edge[i].w;
if(dis[v]<&&w>)
{
dis[v] = dis[u]+;
q.push(v);
}
}
}
if(dis[en]>) return ;
return ;
}
int dfs(int u,int te)
{
int i;
int s;
if(u==en) return te;
for(i = head[u] ; i != - ; i = edge[i].next)
{
int v = edge[i].v;
int w = edge[i].w;
if(w>&&dis[v]==dis[u]+&&(s=dfs(v,min(te,w))))
{
edge[i].w-=s;
edge[i^].w+=s;
return s;
}
}
dis[u] = -;
return ;
}
int dinic()
{
int flow = ;
int res;
while(bfs())
{
while(res = dfs(st,INF))
flow+=res;
}
return flow;
}
int main()
{
int n,i,j;
while(scanf("%d%d%d",&n,&st,&en)!=EOF)
{
init();
// memset(x,0,sizeof(x));
memset(f,,sizeof(f));
st+=n;
for(i = ; i <= n ; i++)
{
for(j = ; j <= n; j++)
{
scanf("%d",&x[i][j]);
if(i==j)
{
add(i,i+n,);
}
else if(x[i][j])
{
add(i+n,j,INF);
}
}
}
if(x[st-n][en])
{
puts("NO ANSWER!");
continue;
}
int ans = dinic();
int cnt = ;
for(i = ; i <= n ; i++)
{
if(ans==) break;
if(i==st-n||i==en) continue;
f[i] = ;
init();
for(j = ; j <= n ; j++)
{
if(f[j]) continue;
for(int e = ; e <= n ; e++)
{
if(f[e]) continue;
if(j==e)
add(j,j+n,);
else if(x[j][e])
{
add(j+n,e,INF);
}
}
}
int ts = dinic();
if(ts<ans)
{
cnt++;
ans = ts;
}
else f[i] = ;
}
cout<<cnt<<endl;
for(j = ; j <= n; j++)
if(f[j])
printf("%d ",j);
printf("\n");
}
return ;
}
poj1815Friendship(最小割求割边)的更多相关文章
- poj 3204(最小割--关键割边)
Ikki's Story I - Road Reconstruction Time Limit: 2000MS Memory Limit: 131072K Total Submissions: 7 ...
- HDU 3251 Being a Hero(最小割+输出割边)
Problem DescriptionYou are the hero who saved your country. As promised, the king will give you some ...
- HDU3987(最小割最少割边)
Harry Potter and the Forbidden Forest Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65536/ ...
- hdu3987,最小割时求最少割边数
题意:求最小割时候割边最少的数量.算法:先求dinic一遍,跑出残网络,再把该网络中满流量(残量为0)的边 残量改为1,其他边残量改为无穷,则再跑一次最大流,所得即为答案.(思,最小割有喝多组,但是要 ...
- HDU - 6214:Smallest Minimum Cut(最小割边最小割)
Consider a network G=(V,E) G=(V,E) with source s s and sink t t . An s-t cut is a partition of nodes ...
- 【HDU4859】 海岸线(网络流-最小割)
Problem Description 欢迎来到珠海! 由于土地资源越来越紧张,使得许多海滨城市都只能依靠填海来扩展市区以求发展.作为Z市的决策人,在仔细观察了Z市地图之后,你准备通过填充某些海域来扩 ...
- 最小割&网络流应用
重要链接 基础部分链接 : 二分图 & 网络流初步 zzz大佬博客链接 : 网络流学习笔记 重点内容:最小割二元关系新解(lyd's ppt) 题目:网络流相关题目 lyd神犇课件链接 : 网 ...
- ZOJ 2753 Min Cut (Destroy Trade Net)(无向图全局最小割)
题目大意 给一个无向图,包含 N 个点和 M 条边,问最少删掉多少条边使得图分为不连通的两个部分,图中有重边 数据范围:2<=N<=500, 0<=M<=N*(N-1)/2 做 ...
- HDU 4859(Bestcoder #1 1003)海岸线(网络流之最小割)
题目地址:HDU4859 做了做杭电多校,知识点会的太少了.还是将重点放在刷专题补知识点上吧,明年的多校才是重点. 这题题目求的最长周长.能够试想一下,这里的海岸线一定是在"."和 ...
随机推荐
- hadoop 集群搭建 配置 spark yarn 对效率的提升永无止境
[手动验证:任意2个节点间是否实现 双向 ssh免密登录] 弄懂通信原理和集群的容错性 任意2个节点间实现双向 ssh免密登录,默认在~目录下 [实现上步后,在其中任一节点安装\配置hadoop后,可 ...
- https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
- hibernate面试点
1.谈谈你对hibernate的认识和理解 01.全自动的ORM框架 02.子项目 03.面向对象的思想来解决操作数据库 01.hibernate是一个开放源代码的对象关系映射(ORM)框架,它对JD ...
- QT下的QThread学习(一)
参考文档如下: http://blog.csdn.net/styyzxjq2009/article/details/8204506 上面这篇文章的开头也也出了另外两篇文章,一并看看,可以看到他的解决思 ...
- 主线程 view
参考https://blog.csdn.net/u011001142/article/details/50912358
- RedisCluster集群原理
主从复制,数据值每个服务器都存了. 针对redis集群的解决方案, 连接这个集群,不用在乎Master了 6台redis 1.why use Redis? 减轻数据库访问压力 2.持久化 RDB(间隔 ...
- 织梦系统如何设置URL绝对路径及绝对路径的好处
今天,和大家分享下织梦系统如何设置URL绝对路径及绝对路径的好处,我的一些就是用的织梦系统,感觉织梦在SEO优化方面做的还是非常好的,至少在CMS系统中应该是做的最出色的吧!下面,我就先来讲下这个织梦 ...
- Android中android:visibility的3中属性的剖析
在Android中控件或者布局的可见性android:visibility有3中情况,他们分别是: View.VISIBLE,View.UNVISIBLE,View.GONE View.VISIBLE ...
- trying to draw too large(106,975,232 bytes) bitmap.
Loading Large Bitmaps Efficiently This lesson teaches you to Read Bitmap Dimensions and Type Load a ...
- VC++读写文件
目录 第1章读写文件 1 1.1 API 1 1.2 低级IO 1 1.2.1 文件序号 1 1.2.2 文本文件与二进制文件 1 1.3 流IO 2 1.4 Un ...