http://poj.org/problem?id=1815

题意:

在现代社会,每个人都有自己的朋友。由于每个人都很忙,他们只通过电话联系。你可以假定A可以和B保持联系,当且仅当:①A知道B的电话号码;②A知道C的电话号码,而C能联系上B。如果A知道B的电话号码,则B也知道A的电话号码。

思路:
这题是要我们删点,既然是删点,那么就要拆点,容量就是1。

接下来凡是能联系的,就连边,容量为INF,因为我们不是要删除这些边。跑遍最大流就能算出至少要删除多少个点。

这道题的关键是要字典序顺序输出最小割的点集,在跑一遍最大流之后,我们按字典序顺序依次枚举每个点,将该点删除后然后再去跑最大流,如果流量减少了,说明它是割点。

 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn = + ; struct Edge
{
int from,to,cap,flow;
Edge(int u,int v,int w,int f):from(u),to(v),cap(w),flow(f){}
}; struct Dinic
{
int n,m,s,t;
vector<Edge> edges;
vector<int> G[maxn];
bool vis[maxn];
int cur[maxn];
int d[maxn]; void init(int n)
{
this->n=n;
for(int i=;i<n;++i) G[i].clear();
edges.clear();
} void AddEdge(int from,int to,int cap)
{
edges.push_back( Edge(from,to,cap,) );
edges.push_back( Edge(to,from,,) );
m=edges.size();
G[from].push_back(m-);
G[to].push_back(m-);
} bool BFS()
{
queue<int> Q;
memset(vis,,sizeof(vis));
vis[s]=true;
d[s]=;
Q.push(s);
while(!Q.empty())
{
int x=Q.front(); Q.pop();
for(int i=;i<G[x].size();++i)
{
Edge& e=edges[G[x][i]];
if(!vis[e.to] && e.cap>e.flow)
{
vis[e.to]=true;
d[e.to]=d[x]+;
Q.push(e.to);
}
}
}
return vis[t];
} int DFS(int x,int a)
{
if(x==t || a==) return a;
int flow=, f;
for(int &i=cur[x];i<G[x].size();++i)
{
Edge &e=edges[G[x][i]];
if(d[e.to]==d[x]+ && (f=DFS(e.to,min(a,e.cap-e.flow) ) )>)
{
e.flow +=f;
edges[G[x][i]^].flow -=f;
flow +=f;
a -=f;
if(a==) break;
}
}
return flow;
} int Maxflow(int s,int t)
{
this->s=s; this->t=t;
int flow=;
while(BFS())
{
memset(cur,,sizeof(cur));
flow +=DFS(s,INF);
}
return flow;
}
}DC; int n,s,t;
int mp[maxn][maxn]; int main()
{
//freopen("in.txt","r",stdin);
while(~scanf("%d%d%d",&n,&s,&t))
{
int dst=*n+;
DC.init(dst+); for(int i=;i<=n;i++)
{
if(i==s || i==t) DC.AddEdge(i,i+n,INF);
else DC.AddEdge(i,i+n,);
} for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
scanf("%d",&mp[i][j]);
if(i==j) continue;
if(mp[i][j]) DC.AddEdge(i+n,j,INF);
}
} if(mp[s][t]) {puts("NO ANSWER!");continue;} int cnt=DC.Maxflow(s,t);
vector<int> ans; printf("%d\n",cnt);
if(cnt==) continue; for(int i=;i<*n;i+=) //前2*n条边为每个顶点,依次枚举
{
Edge& e=DC.edges[i];
if(e.from==s || e.from==t) continue;
e.cap=; //删边
for(int j=;j<*n;j++) DC.edges[j].flow = ;
int tmp=DC.Maxflow(s,t); //如果流量改变,说明这条边是割边
if(tmp<cnt)
{
cnt=tmp;
ans.push_back(e.from);
}
else e.cap=;
if(cnt<=) break;
}
for(int i=;i<ans.size();i++)
{
printf("%d%c",ans[i],i==ans.size()-?'\n':' ');
}
printf("\n");
}
return ;
}

POJ 1815 Friendship(最小割+字典序输出割点)的更多相关文章

  1. POJ 1815 Friendship(最小割)

    http://poj.org/problem? id=1815 Friendship Time Limit: 2000MS   Memory Limit: 20000K Total Submissio ...

  2. poj 1815 Friendship (最小割+拆点+枚举)

    题意: 就在一个给定的无向图中至少应该去掉几个顶点才干使得s和t不联通. 算法: 假设s和t直接相连输出no answer. 把每一个点拆成两个点v和v'',这两个点之间连一条权值为1的边(残余容量) ...

  3. POJ - 1815 Friendship (最小点割集)

    (点击此处查看原题) 题目分析 题意:有n个人,编号记为1~n,n个人之间可能有人可以互相联系,如果A能和B联系,那么至少满足这两种情况之一:(1)A知道B的电话(2)A可以和C联系,并且C可以和B联 ...

  4. poj 1815(最小割、割集)

    题目链接:http://poj.org/problem?id=1815 思路:题目要求是剔除多少个点,可以将其转化为剔除多少条边,因此需要拆点,将点i拆成i,i+n,便容量为1,表示每个人起的传递作用 ...

  5. POJ 1815 Friendship(字典序最小的最小割)

    Friendship Time Limit: 2000MS   Memory Limit: 20000K Total Submissions: 10744   Accepted: 2984 Descr ...

  6. poj 1815 Friendship 字典序最小+最小割

    题目链接:http://poj.org/problem?id=1815 In modern society, each person has his own friends. Since all th ...

  7. POJ 1815 Friendship (Dinic 最小割)

    Friendship Time Limit: 2000MS   Memory Limit: 20000K Total Submissions: 8025   Accepted: 2224 Descri ...

  8. POJ 1815 Friendship(最大流最小割の字典序割点集)

    Description In modern society, each person has his own friends. Since all the people are very busy, ...

  9. POJ 1815 Friendship ★(字典序最小点割集)

    [题意]给出一个无向图,和图中的两个点s,t.求至少去掉几个点后才能使得s和t不连通,输出这样的点集并使其字典序最大. 不错的题,有助于更好的理解最小割和求解最小割的方法~ [思路] 问题模型很简单, ...

随机推荐

  1. OneThink后台模型怎么玩?

    OneThink 后台模型有个模型类型: 模型下——>设计——>表单显示分组(怎么玩?) 这个将会显示在:内——>发布文章内容的时候: 单选按钮: 内容模块显示: 枚举类型可以这样玩 ...

  2. hdu4975 网络流解方程组(网络流+dfs判环或矩阵DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=4975 A simple Gaussian elimination problem. Time Limit: 20 ...

  3. spring 配置中相关属性的含义:

    1:parent元素属性 一个bean定义可能会包含大量的配置信息,包括容器相关的信息(比如初始化方法,静态工厂方法等等)以及构造函数参数和属性的值.一个child bean定义是一个能够从paren ...

  4. Python 中的map函数,filter函数,reduce函数

      自学python,很多地方都需要恶补.       三个函数比较类似,都是应用于序列的内置函数.常见的序列包括list.tuple.str.   1.map函数 map函数会根据提供的函数对指定序 ...

  5. Spring源码学习之IOC实现原理(二)-ApplicationContext

    一.Spring核心组件结构 总的来说Spring共有三个核心组件,分别为Core,Context,Bean.三大核心组件的协同工作主要表现在 :Bean是包装我们应用程序自定义对象Object的,O ...

  6. wireshark, loopback

    swapondd if=/dev/zero of=/data/mnt/swap bs=1024 count=8024000 sudo apt-get install wireshark sudo gr ...

  7. 用tsunami-udp加速网络传输

    概述 tsunami-udp是一款专为网络加速诞生的小工具. 思路很简单,使用TCP进行传输控制.UDP进行数据传输. 这样可以无状态的进行数据传输,然后中间加一些文件校验和重传机制,达到加速传输的目 ...

  8. Linux下编译安装MySQL5.6

    [准备工作] 所有操作需要在root用户下 本机测试案例系统信息:centos7.3 安装路径:/usr/local/mysql [安装MySQL] 先安装如下依赖包: $ yum -y instal ...

  9. 基于Kafka+Spark Streaming+HBase实时点击流案例

    背景 Kafka实时记录从数据采集工具Flume或业务系统实时接口收集数据,并作为消息缓冲组件为上游实时计算框架提供可靠数据支撑,Spark 1.3版本后支持两种整合Kafka机制(Receiver- ...

  10. 上传文件小的oK,大一点的传不了,显示 (failed) net::ERR_CONNECTION_RESET

    我很确定已经修改了php.ini中的文件上传限制,文件权限可写. 修改php.ini file_uploads = on ;是否允许通过HTTP上传文件的开关.默认为ON即是开 upload_tmp_ ...