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 做了做杭电多校,知识点会的太少了.还是将重点放在刷专题补知识点上吧,明年的多校才是重点. 这题题目求的最长周长.能够试想一下,这里的海岸线一定是在"."和 ...
随机推荐
- LIS(最长上升子序列)的三种经典求法
求最长上升子序列的三种经典方案: 给定一个长度为 \(N\) 的数列,求它数值单调递增的子序列长度最大为多少.即已知有数列 \(A\) , \(A=\{A_1,A_2....A_n\}\) ,求 \( ...
- Jmeter代理服务器录制请求
1.文档前提说明 1)本文使用jmeter的版本为 apache-jmeter-2.13 及以上版本 2)java版本要求在 1.8.0 以上 注:jmeter版本一般和java相应的版本一起使用,如 ...
- (linux)初学者学linux块设备驱动
面对不断升级的linux内核.GNU开发工具.linux环境下的各种图形库,很多linux应用程序开发人员和linux设备驱动开发人员即兴奋,又烦躁.兴奋的是新的软件软件.工具给我提供了更强大的功 ...
- hadoop异常:Be Replicated to 0 nodes, instead of 1
Hadoop 坑爹的Be Replicated to 0 nodes, instead of 1 异常 博客分类: Java 编程 HadoopITeyeJSP算法Apache 有段时间不写博客了, ...
- UVA-10391(字符串检索)
题意: 给定一个字典,要求找出所有的复合词; 思路: 用map把词都存起来,再把词拆开看是否是出现过的单词; AC代码: #include <bits/stdc++.h> #include ...
- 西交校赛 F. GZP and Poker
F. GZP and Poker GZP often plays games with his friends.Today they went to a board game.There are n ...
- I.MX6 2014 u-boot 测试修改
/************************************************************************* * I.MX6 2014 u-boot 测试修改 ...
- AutoIt:获取计算机已安装程序列表
$file = FileOpen(@ScriptDir&"\RegInstalledItems.csv",1) if $file = -1 Then ConsoleWrit ...
- Ubuntu中字体的改变
1.sudo dpkg-reconfigure console-setup 2.弹出 Configuring console-setup 界面,选择适当的编码格式,我们一般选择默认的UTF-8,选择O ...
- E20170510-hm
prototype n. 原型,雏形,蓝本; omit (omitted) vt. 省略; 遗漏; autonomous adj. 自治的; 有自主权的; fold ...