Least Crucial Node

题目链接:

http://acm.hust.edu.cn/vjudge/contest/127401#problem/C

Description


http://7xjob4.com1.z0.glb.clouddn.com/e15d7d11650607e5795d28e1120d7109

Input


There are several input lines to a test case. The first line of each test case contains an integer n
(2 ≤ n ≤ 100), where n is the number of nodes (vertex set of G) labeled with {1, 2, . . . , n} in the
network. The second line contains an integer, which is the label of the unique sink of the network. The
third line contains an integer m, indicating the number of communication links in the network. The
next m lines each contains a pair of integers, say i and j (separated by a space), denoting there is a
communication link (edge in E) between node i and node j. There are at most 10 test cases and n = 0
denotes end of the test cases.

Output


The output for each instance should contain an integer denoting the least crucial node in the given
network.

Sample Input


4
4
3
1 2
2 3
3 4
6
3
8
1 2
2 3
2 4
2 5
3 4
3 5
4 5
5 6
0

Sample Output


3
2


##题意:

求标号最小的最大割点.
(删除该点后,指定点#sink能到达的点数减少最多).


##题解:

由于数据规模巨水,直接对枚举各点跑一遍并查集(或dfs)计算删除后的减少量.
(不要对源点#sink跑并查集,因为割点不能是#sink).


##代码:
``` cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long
#define eps 1e-8
#define maxn 110
#define mod 100000007
#define inf 0x3f3f3f3f
#define mid(a,b) ((a+b)>>1)
#define IN freopen("in.txt","r",stdin);
using namespace std;

int fa[maxn];

int _rank[maxn];

void init() {

for(int i=0; i<maxn; i++) {

fa[i] = i;

_rank[i] = 0;

}

}

int find_set(int x) {

return x==fa[x]? x:find_set(fa[x]);

}

void unit_set(int x, int y) {

x = find_set(x);

y = find_set(y);

if(_rank[x] < _rank[y]) swap(x,y);

fa[y] = x;

if(_rank[x] == _rank[y]) _rank[x]++;

}

int x[maxnmaxn], y[maxnmaxn];

int main(int argc, char const *argv[])

{

//IN;

int n;
while(scanf("%d", &n) != EOF && n)
{
int sink, m;
scanf("%d %d", &sink, &m);
int ans = 0; int init_ans = 0;
init();
for(int i=1; i<=m; i++) {
scanf("%d %d", &x[i], &y[i]);
unit_set(x[i], y[i]);
} for(int i=1; i<=n; i++) {
if(find_set(i) == find_set(sink)) init_ans++;
} int p_ans = 0;
for(int i=1; i<=n; i++) if(i!=sink){
init();
for(int j=1; j<=m; j++) {
if(x[j]==i || y[j]==i) continue;
unit_set(x[j], y[j]);
}
int cnt = 0;
for(int j=1; j<=n; j++) {
if(find_set(j) == find_set(sink)) cnt++;
} if(init_ans-cnt > ans) {
ans = init_ans - cnt;
p_ans = i;
}
} printf("%d\n", p_ans); //a
} return 0;

}

UVALive 7456 Least Crucial Node (并查集)的更多相关文章

  1. UVaLive 7456 Least Crucial Node (并查集+暴力 或者 求割点)

    题意:求标号最小的最大割点.(删除该点后,指定点#sink能到达的点数减少最多). 析:由于不知道要去掉哪个结点,又因为只有100个结点,所以我们考虑用一个暴力,把所有的结点都去一次,然后用并查集去判 ...

  2. UVALive 7456 Least Crucial Node

    题目链接 题意: 给定一个无向图,一个汇集点,问哪一个点是最关键的,如果有多个关键点,输出序号最小的那个. 因为数据量比较小,所以暴力搜索就行,每去掉一个点,寻找和汇集点相连的还剩几个点,以此确定哪个 ...

  3. UVALive - 6910 (离线逆序并查集)

    题意:给处编号从1~n这n个节点的父节点,得到含有若干棵树的森林:然后再给出k个操作,分两种'C x'是将节点x与其父节点所连接的支剪短:'Q a b'是询问a和b是否在同一棵树中. 题解:一开始拿到 ...

  4. uvalive 4730王国kingdom(并查集+线段树)

     题意:有T组測试数据.每组数据的N表示有N个城市,接下来的N行里每行给出每一个城市的坐标(0<=x,y<=1000000),然后有M(1<M<200000)个操作,操作有 ...

  5. UVALive 6910 Cutting Tree(并查集应用)

    总体来说,这个题给的时间比较长,样例也是比较弱的,别的方法也能做出来. 我第一次使用的是不合并路径的并查集,几乎是一种暴力,花了600多MS,感觉还是不太好的,发现AC的人很多都在300MS之内的过得 ...

  6. UVALive - 5031 Graph and Queries (并查集+平衡树/线段树)

    给定一个图,支持三种操作: 1.删除一条边 2.查询与x结点相连的第k大的结点 3.修改x结点的权值 解法:离线倒序操作,平衡树or线段树维护连通块中的所有结点信息,加个合并操作就行了. 感觉线段树要 ...

  7. POJ 1308/并查集

    题目链接 /* 判断一棵树: * 1.There is exactly one node, called the root, to which no directed edges point. * 2 ...

  8. UVALive 6910 Cutting Tree(离线逆序并查集)

    [题目]:(地址:) http://acm.hust.edu.cn/vjudge/contest/view.action?cid=97671#problem/E [题意]: 给出多棵树和两类操作:操作 ...

  9. UVALive 6187 Never Wait for Weights 带权并查集

    题意:每次给出每两个数之间的大小差值.在给出关系的过程中插入询问:数a和数b的差值,若不能确定,输出UNKNOWN 解法:相对大小关系的处理:并查集 1.给出两点的相对大小关系后,找到两个点的根节点, ...

随机推荐

  1. ffmpeg 2.8.1 最新版本 VS2013 可调式动态库

    ffmpeg 2.8.1 最新版本 VS2013 可调式动态库 由于大多数初学者都在想尽各种版本寻求VC编译调试ffmpeg的版本,我也曾经移植过几个版本的ffmpeg到VC上编译.: 链接所需动态库 ...

  2. GIT使用教程与基本原理

    转自:http://blog.csdn.net/wengpingbo/article/details/8985132 说明:该教程全部图片都来自于<pro git>.以下所有的操作,除非特 ...

  3. 【转载】React入门-Todolist制作学习

    我直接看的这个React TodoList的例子(非常好!): http://www.reqianduan.com/2297.html 文中示例的代码访问路径:http://127.0.0.1:708 ...

  4. Mysql,SqlServer,Oracle主键自动增长的设置

    1.把主键定义为自动增长标识符类型 MySql 在mysql中,如果把表的主键设为auto_increment类型,数据库就会自动为主键赋值.例如: )); insert into customers ...

  5. 搭建LAMP测试环境

    LAMP:Linux+Apache+Mysql+Php,组合统称为LAMP,关于其中的独立个体,这里就不多介绍了. 1.首先准备一下软件包,如下: mysql-5.0.22.tar.gz httpd- ...

  6. (5)Quartz学习

    原文:http://blog.csdn.net/zxl315/article/details/10879927 介绍Quartz Quartz是一个开源的任务调度系统,它能用来调度很多任务的执行. 运 ...

  7. 常见MyEclipse报错—— serialVersionUID的作用

    先挖好坑 http://swiftlet.net/archives/1268

  8. 【html】页面制作规范文档

    每天都在写html/css/js代码,总结的一些页面制作的规范 文件命名规范 1) 文件目录.文件名称统一用小写的英文字母.数字.下划线组合,文件名要与表现的内容相近,不到万不得已不要以拼音作为名称, ...

  9. GreenDao官方文档翻译(上)

    笔记摘要: 上一篇博客简单介绍了SQLite和GreenDao的比较,后来说要详细介绍下GreenDao的使用,这里就贴出本人自己根据官网的文档进行翻译的文章,这里将所有的文档分成上下两部分翻译,只为 ...

  10. windows批处理中的%0 %1 %2 %3

    原来就是参数的顺序.....倒...我还查了老半天