一个无向图,问你删除多少点后,可以隔断起点到终点的所有路径?输出字典序最小的删点方案。

求最小点割,先拆点,容量为1,普通边容量无穷,最大流即为应删点数。

需要求出字典序最小的方案,可以从小到大枚举所有的点,如果当前枚举的点是割点,那么进行标记,同时后面的枚举也不再经过这个点。

召唤代码君:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#define maxn 5555
#define maxm 555555
using namespace std; int to[maxm],next[maxm],c[maxm],belong[maxm],first[maxm],edge;
int d[maxn],tag[maxn],TAG=;
bool can[maxn],go[maxn];
int Q[maxn],bot,top;
int f[][];
int s,t,n,pos[maxn]; void _init()
{
edge=-;
for (int i=; i<=n+n; i++) first[i]=-,go[i]=false;
} void addedge(int U,int V)
{
edge++;
to[edge]=V,c[edge]=,next[edge]=first[U],first[U]=edge;
edge++;
to[edge]=U,c[edge]=,next[edge]=first[V],first[V]=edge;
} bool bfs()
{
Q[bot=top=]=t,tag[t]=++TAG,d[t]=,can[t]=false;
while (bot<=top)
{
int cur=Q[bot++];
for (int i=first[cur]; i!=-; i=next[i])
if (c[i^]> && tag[to[i]]!=TAG && !go[to[i]])
{
tag[to[i]]=TAG,d[to[i]]=d[cur]+;
can[to[i]]=false,Q[++top]=to[i];
if (to[i]==s) return true;
}
}
return false;
} int dfs(int cur,int num)
{
if (cur==t) return num;
int tmp=num,k;
for (int i=first[cur]; i!=-; i=next[i])
if (c[i]> && tag[to[i]]==TAG && d[to[i]]==d[cur]- && !can[to[i]])
{
k=dfs(to[i],min(num,c[i]));
if (k) num-=k,c[i]-=k,c[i^]+=k;
if (!num) break;
}
if (num) can[cur]=true;
return tmp-num;
} int maxflow()
{
int flow=;
while (bfs()) flow+=dfs(s,~0U>>);
return flow;
} int get(int x)
{
for (int i=first[x]; i!=-; i=next[i])
if (c[i]== && !(i&))
{
int tmp=to[i];
tmp-=x;
if (tmp<) tmp=-tmp;
if (tmp!=n) return get(to[i]);
tmp=min(x,to[i]);
return min(tmp,get(to[i]));
}
return ~0U>>;
} int main()
{
int tmp,mf;
vector<int> ans;
while (scanf("%d%d%d",&n,&s,&t)!=EOF)
{
_init();
for (int i=; i<=n; i++) addedge(i,i+n),pos[i]=edge;
for (int i=; i<=n; i++)
for (int j=; j<=n; j++)
{
scanf("%d",&tmp);
f[i][j]=f[j][i]=tmp;
if (i>=j) continue;
if (tmp) addedge(i+n,j),addedge(j+n,i);
}
if (s==t || f[s][t])
{
puts("NO ANSWER!");
continue;
}
s+=n;
ans.clear();
mf=maxflow();
printf("%d\n",mf);
if (mf==) continue;
for (int i=; i<=n && mf>; i++)
{
if (i==s-n || i==t) continue;
for (int j=; j<edge; j+=) c[j]+=c[j+],c[j+]=;
go[i]=true,go[i+n]=true;
tmp=maxflow();
if (tmp<mf) ans.push_back(i),mf--;
else go[i]=false,go[i+n]=false;
} sort(ans.begin(),ans.end());
printf("%d",ans[]);
for (unsigned i=; i<ans.size(); i++) printf(" %d",ans[i]);
printf("\n");
}
return ;
}

POJ1815_Friendship的更多相关文章

随机推荐

  1. [webapp]移动平台各浏览器的分辨率适配

    搞webapp适配了N多浏览器,记一下各浏览器碰到的需要注意的地方. 目前发现firefox是最难适配的. 1.firefox只有在onload之后才能取到正确的innerwidth值. 2.目前版本 ...

  2. 关于Memcached 你了解多少?

    好久没有写博客了,自从年后到现在要么就是加班 要么还是在加班 基本都是到夜里1点多 通宵的干,事情太多,项目太急  .难得今天闲暇一段时间来,看看书,写一写博客,没事就再重新的研究一下关于Memcac ...

  3. 为什么 Action/ViewController/ProperttyEditor不可见或不可用?

    英文版:https://documentation.devexpress.com/eXpressAppFramework/112818/Concepts/Extend-Functionality/De ...

  4. postMan测试Controller接口

    1.介绍 Postman是一款功能强大的网页调试与发送网页HTTP请求的Chrome插件. 2.安装 Postman 4.1.2 下载地址: http://files.cnblogs.com/file ...

  5. 【转】Linux系统下的ssh使用

    Linux系统下的ssh使用(依据个人经验总结)   对于linux运维工作者而言,使用ssh远程远程服务器是再熟悉不过的了!对于ssh的一些严格设置也关系到服务器的安全维护,今天在此,就本人工作中使 ...

  6. python继承与多继承

    1.类与对象里的父类与子类(继承): 类的继承主要是指自子类对于之前父类的方法的继承,如果子类里面写了父类里的方法,则它会将父类里的方法覆盖掉,从而不能再调用到父类的方法. 2.为了解决父类与子类里的 ...

  7. Flink BLOB架构

    Flink中支持的BLOB文件类型 jar包 被user classloader使用的jar包 高负荷RPC消息 1. RPC消息长度超出了akka.framesize的大小 2. 在HA摸式中,利用 ...

  8. 04-matplotlib-柱形图

    import numpy as np import matplotlib.pyplot as plt # 柱形图 # 例一 N =5 y = [15,28,10,30,25] index = np.a ...

  9. 获400 万美元 A 轮融资,ShipBob 想帮助小微企业享受Amazon Prime 级配送服务 2016-06-18

    Weiss认为,无论零售市场的发展走向如何波动,ShipBob公司都能够获得坚实的成长表现. 在线销售实体商品的小型企业当然希望利用种种方式取悦客户,但面对着Amazon Prime迅如闪电且价格实惠 ...

  10. [leetcode-897-Increasing Order Search Tree]

    Given a tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root o ...