链接

题意为去掉多少个顶点使图不连通,求顶点连通度问题。拆点,构造图,对于<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(最小割求割边)的更多相关文章

  1. poj 3204(最小割--关键割边)

    Ikki's Story I - Road Reconstruction Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 7 ...

  2. HDU 3251 Being a Hero(最小割+输出割边)

    Problem DescriptionYou are the hero who saved your country. As promised, the king will give you some ...

  3. HDU3987(最小割最少割边)

    Harry Potter and the Forbidden Forest Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65536/ ...

  4. hdu3987,最小割时求最少割边数

    题意:求最小割时候割边最少的数量.算法:先求dinic一遍,跑出残网络,再把该网络中满流量(残量为0)的边 残量改为1,其他边残量改为无穷,则再跑一次最大流,所得即为答案.(思,最小割有喝多组,但是要 ...

  5. 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 ...

  6. 【HDU4859】 海岸线(网络流-最小割)

    Problem Description 欢迎来到珠海! 由于土地资源越来越紧张,使得许多海滨城市都只能依靠填海来扩展市区以求发展.作为Z市的决策人,在仔细观察了Z市地图之后,你准备通过填充某些海域来扩 ...

  7. 最小割&网络流应用

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

  8. ZOJ 2753 Min Cut (Destroy Trade Net)(无向图全局最小割)

    题目大意 给一个无向图,包含 N 个点和 M 条边,问最少删掉多少条边使得图分为不连通的两个部分,图中有重边 数据范围:2<=N<=500, 0<=M<=N*(N-1)/2 做 ...

  9. HDU 4859(Bestcoder #1 1003)海岸线(网络流之最小割)

    题目地址:HDU4859 做了做杭电多校,知识点会的太少了.还是将重点放在刷专题补知识点上吧,明年的多校才是重点. 这题题目求的最长周长.能够试想一下,这里的海岸线一定是在"."和 ...

随机推荐

  1. 最长公共上升子序列 (poj 2127) (Greatest Common Increasing Subsequence)

    \(Greatest Common Increasing Subsequence\) 大致题意:给出两个长度不一定相等的数列,求其中最长的公共的且单调递增的子序列(需要具体方案) \(solution ...

  2. js中return的作用

    1.终止函数的继续运行. 当遇到if…… else是.若出现return,就会出现终止运行,不会继续做出判断 <html> <head> <title>return ...

  3. 异常、Throwable、finally、File类(十九)

    1.异常的概述和分类 * A:异常的概述 * 异常就是Java程序在运行过程中出现的错误.* B:异常的分类 * 通过API查看Throwable * Error * 服务器宕机,数据库崩溃等 * E ...

  4. .NET 4.0 System.Threading.Tasks学习笔记

    由于工作上的需要,学习使用了System.Threading.Tasks的使用,特此笔记下来. System.Threading.Tasks的作用: Tasks命名空间下的类试图使用任务的概念来解决线 ...

  5. magento导入数据的方法

    导入演示数据 分两种情况处理. 如果你是用composer方式安装的 非常简单,二行命令搞定:在项目根目录下执行.我们的是在/var/www/magento2/下面. 安装演示数据 php bin/m ...

  6. BZOJ_1492_[NOI2007]货币兑换Cash_CDQ分治+斜率优化

    BZOJ_1492_[NOI2007]货币兑换Cash_CDQ分治+斜率优化 Description 小Y最近在一家金券交易所工作.该金券交易所只发行交易两种金券:A纪念券(以下简称A券)和 B纪念券 ...

  7. Watir: 如果安装sougou浏览器,有可能导致Watir不能工作

    如果安装了搜狗,Watir::Browser.new并不一定能打开新的IE浏览器.这种情况下,必须卸载搜狗浏览器,当然,attach,find方法还是可以用的

  8. MySQL_详细基本操作命令

    mysql 修改新密码:use mysql:update user set password='新密码' where user='用户名':flush privileges:  更新权限 增加新用户: ...

  9. 【201】SeaDAS代码

    参考: 官方网站:http://seadas.gsfc.nasa.gov/ L2GEN User's Guide l2gen 代码: l2gen, ifile="ifile", g ...

  10. Asp.net MVC 使用PagedList(新的已更名 为X.PagedList.Mvc) 分页

    在asp.net mvc 中,可以bootstrap来作为界面,自己来写分页程序.也可以使用PagedList(作者已更名为 X.PagedList.Mvc)来分页. 1.首先,在NuGet程序包管理 ...