【题意】给出一个无向图,和图中的两个点s,t。求至少去掉几个点后才能使得s和t不连通,输出这样的点集并使其字典序最大。

不错的题,有助于更好的理解最小割和求解最小割的方法~

【思路】

问题模型很简单,就是无向图的点连通度,也就是最小点割集。麻烦之处在于需要使得点割集方案的字典序最大。这样的话通常的dfs划分点集的方法就行不通了。我们采取贪心的策略:枚举1~N的点,在残留网络中dfs检查其代表的边的两端点是否连通,如果不连通则该点可以为点割,那么我们就让他是点割,加入到答案中,然后删掉这条边更新最大流。重复这个过程直到扫描完所有点。

PS:很多人判断点是否可以是点割时是先删掉边然后判断流是否减小,我觉得这样是不是麻烦了?因为如果不减小的话(不是点割)还得把他还原,相当于重新构了两次图。

#include
#include
#include
#include
#include
#include
#define MID(x,y) ((x+y)/2)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int MAXV = 505;
const int MAXE = 50005;
const int oo = 0x3fffffff;

/* Dinic-2.0-2013.07.21: adds template. double & int 转换方便多了,也不易出错 ~*/
template
struct Dinic{
struct node{
int u, v;
T flow;
int opp;
int next;
}arc[2*MAXE];
int vn, en, head[MAXV];
int cur[MAXV];
int q[MAXV];
int path[2*MAXE], top;
int dep[MAXV];
void init(int n){
vn = n;
en = 0;
mem(head, -1);
}
void insert_flow(int u, int v, T flow){
arc[en].u = u;
arc[en].v = v;
arc[en].flow = flow;
arc[en].next = head[u];
head[u] = en ++;

arc[en].u = v;
arc[en].v = u;
arc[en].flow = 0;
arc[en].next = head[v];
head[v] = en ++;
}
bool bfs(int s, int t){
mem(dep, -1);
int lq = 0, rq = 1;
dep[s] = 0;
q[lq] = s;
while(lq 0){
dep[v] = dep[u] + 1;
q[rq ++] = v;
}
}
}
return false;
}
T solve(int s, int t){
T maxflow = 0;
while(bfs(s, t)){
int i, j;
for (i = 1; i arc[path[k]].flow){
minflow = arc[path[k]].flow;
mink = k;
}
for (int k = 0; k dinic;

bool map[MAXV][MAXV];
int n, s, t;
bool vis[MAXV];
bool dfs(int u, int t){
vis[u] = 1;
if (u == t)
return true;
for (int i = dinic.head[u]; i != -1; i = dinic.arc[i].next){
if (dinic.arc[i].flow mincut;
mem(del, false);
if (res){
for (int i = 1; i

POJ 1815 Friendship ★(字典序最小点割集)的更多相关文章

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

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

  2. POJ 1815 Friendship(最小割+字典序输出割点)

    http://poj.org/problem?id=1815 题意: 在现代社会,每个人都有自己的朋友.由于每个人都很忙,他们只通过电话联系.你可以假定A可以和B保持联系,当且仅当:①A知道B的电话号 ...

  3. poj 1815 Friendship【最小割】

    网络流的题总是出各种奇怪的错啊--没写过邻接表版的dinic,然后bfs扫到t点不直接return 1就会TTTTTLE-- 题目中的操作是"去掉人",很容易想到拆点,套路一般是( ...

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

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

  5. POJ 1815 - Friendship - [拆点最大流求最小点割集][暴力枚举求升序割点] - [Dinic算法模板 - 邻接矩阵型]

    妖怪题目,做到现在:2017/8/19 - 1:41…… 不过想想还是值得的,至少邻接矩阵型的Dinic算法模板get√ 题目链接:http://poj.org/problem?id=1815 Tim ...

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

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

  7. POJ 1815 Friendship(最小割)

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

  8. POJ 1815 Friendship (Dinic 最小割)

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

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

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

随机推荐

  1. Programming Collective Intelligence

    最近正在拜读 O'reilly出版的Programming Collective Intelligence,准备研究研究搜索引擎了,童鞋们,到时候会考虑公布源码哦!

  2. MacOS10.9获取Android源码不完全笔记(2014)

    第一步:安装Macports 这个我就不叙述了,网上有无数教程 第二步:创建一个磁盘镜像 1.打开磁盘工具,然后: 第三步:使用Macport安装编译环境 1.打开终端输入以下内容 sudo port ...

  3. 干货CentOS6.5_Nginx1.40_Php5.57_MySQL5.5.35编译安装全记录

    http://www.unixdo.com/Unix_Linux/CentOS65_Nginx140_Php557_MySQL5535.html 如果是编译升级php,之前做过nginx的虚拟主机配置 ...

  4. easy ui 下拉级联效果 ,下拉框绑定数据select控件

    html代码: ①两个下拉框,一个是省,另一个市 <tr> <td>省:</td> <td> <select id="ProvinceI ...

  5. js学习之函数表达式及闭包

    来自<javascript高级程序设计 第三版:作者Nicholas C. Zakas>的学习笔记(七) 直接切入主题~ 定义函数的方式有两种: 函数声明 function functio ...

  6. PAT-乙级-1044. 火星数字(20)

    1044. 火星数字(20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 火星人是以13进制计数的: 地球人的 ...

  7. DeepFace--Facebook的人脸识别(转)

    DeepFace基本框架 人脸识别的基本流程是: detect -> aligh -> represent -> classify 人脸对齐流程 分为如下几步: a. 人脸检测,使用 ...

  8. python:UnicodeEncodeError

    problem: (<type 'exceptions.UnicodeEncodeError'>, UnicodeEncodeError('ascii', u'[taobao_cocobe ...

  9. 1030-ACM程序设计之马拉松竞赛

    描述 校ACM协会近四个月举行了为期100天ACM程序设计之马拉松竞赛,竞赛题总数为1000,同学们反响热烈,先后有许多ACM程序设计竞赛爱好者开始先后编号,成功解答的题目数为选手的成绩. 今天进行成 ...

  10. java Tomcat数据库连接池

    1. 在tomcat服务器目录下面的conf中找到一个叫Context.xml的配置文件,在其中加入以下代码 <Resource name="jdbc/books"  aut ...