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. linux下远程服务器批量执行命令及SFTP上传文件 -- python实现

    之前写过一个python远程执行命令的脚本,但在一个性能测试中,要将程序批量分发到不同服务器,程序无法使用,再将之前的脚本更新,加入批量上传的功能.之前脚本地址:http://www.cnblogs. ...

  2. maven指定项目的构建、打包和tomcat插件的pom.xml配置

    1.pom.xml添加如下配置: <build> <finalName>${parent.artifactId}</finalName> <plugins&g ...

  3. mac必备软件

    LigthPaper:Markdown工具 ssh工具:ShellCraft

  4. MegaCli 监控raid状态 限戴尔服务器

    MegaCli 监控raid状态 MegaCli是一款管理维护硬件RAID软件,可以通过它来了解当前raid卡的所有信息,包括 raid卡的型号,raid的阵列类型,raid 上各磁盘状态,等等.通常 ...

  5. java-mybaits-00103-入门程序原生的【查、增、删、改】

    一.需求 实现以下功能: 根据用户id查询一个用户信息 根据用户名称模糊查询用户信息列表 添加用户 更新用户 删除用户 二.具体步骤 1.增加pom引用 2.增加log4j.properties # ...

  6. 使用Rxjava自己创建RxBus

    https://piercezaifman.com/how-to-make-an-event-bus-with-rxjava-and-rxandroid/ https://lingyunzhu.git ...

  7. Django REST framework 之JWT认证

    Json Web Token 1.JWT简介 JWT 是一个开放标准(RFC 7519),它定义了一种用于简洁,自包含的用于通信双方之间以 JSON 对象的形式安全传递信息的方法.JWT 可以使用 H ...

  8. vmware克隆虚拟机

    克隆步骤 右键需要克隆的虚拟机 > 管理,在克隆向导中选择完整克隆. 实验环境:win10_64bit + vmware 12 pro + CentOS6.9_64bit 克隆之后网络配置 克隆 ...

  9. php生成二维码的几种方式

    一些php生成二维码的方式:1.google开放api:2.php类库PHP QR Code:3.libqrencode:4.QRcode Perl CGI & PHP scripts 1.g ...

  10. WCF For Silverlight跨域策略

    在WCF的根目录下添加跨域文件 <?xml version="1.0" encoding="utf-8" ?> <access-policy& ...