UVALive 7456 Least Crucial Node (并查集)
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 (并查集)的更多相关文章
- UVaLive 7456 Least Crucial Node (并查集+暴力 或者 求割点)
题意:求标号最小的最大割点.(删除该点后,指定点#sink能到达的点数减少最多). 析:由于不知道要去掉哪个结点,又因为只有100个结点,所以我们考虑用一个暴力,把所有的结点都去一次,然后用并查集去判 ...
- UVALive 7456 Least Crucial Node
题目链接 题意: 给定一个无向图,一个汇集点,问哪一个点是最关键的,如果有多个关键点,输出序号最小的那个. 因为数据量比较小,所以暴力搜索就行,每去掉一个点,寻找和汇集点相连的还剩几个点,以此确定哪个 ...
- UVALive - 6910 (离线逆序并查集)
题意:给处编号从1~n这n个节点的父节点,得到含有若干棵树的森林:然后再给出k个操作,分两种'C x'是将节点x与其父节点所连接的支剪短:'Q a b'是询问a和b是否在同一棵树中. 题解:一开始拿到 ...
- uvalive 4730王国kingdom(并查集+线段树)
题意:有T组測试数据.每组数据的N表示有N个城市,接下来的N行里每行给出每一个城市的坐标(0<=x,y<=1000000),然后有M(1<M<200000)个操作,操作有 ...
- UVALive 6910 Cutting Tree(并查集应用)
总体来说,这个题给的时间比较长,样例也是比较弱的,别的方法也能做出来. 我第一次使用的是不合并路径的并查集,几乎是一种暴力,花了600多MS,感觉还是不太好的,发现AC的人很多都在300MS之内的过得 ...
- UVALive - 5031 Graph and Queries (并查集+平衡树/线段树)
给定一个图,支持三种操作: 1.删除一条边 2.查询与x结点相连的第k大的结点 3.修改x结点的权值 解法:离线倒序操作,平衡树or线段树维护连通块中的所有结点信息,加个合并操作就行了. 感觉线段树要 ...
- POJ 1308/并查集
题目链接 /* 判断一棵树: * 1.There is exactly one node, called the root, to which no directed edges point. * 2 ...
- UVALive 6910 Cutting Tree(离线逆序并查集)
[题目]:(地址:) http://acm.hust.edu.cn/vjudge/contest/view.action?cid=97671#problem/E [题意]: 给出多棵树和两类操作:操作 ...
- UVALive 6187 Never Wait for Weights 带权并查集
题意:每次给出每两个数之间的大小差值.在给出关系的过程中插入询问:数a和数b的差值,若不能确定,输出UNKNOWN 解法:相对大小关系的处理:并查集 1.给出两点的相对大小关系后,找到两个点的根节点, ...
随机推荐
- HDFS 小文件处理——应用程序实现
在真实环境中,处理日志的时候,会有很多小的碎文件,但是文件总量又是很大.普通的应用程序用来处理已经很麻烦了,或者说处理不了,这个时候需要对小文件进行一些特殊的处理——合并. 在这通过编写java应用程 ...
- mac更新node
今天在用 yeoman 的时候,提示对 npm 和 node 的版本有要求,为了决绝以后遇到的一些类似的问题,我决定定期对 node 和 npm 进行更新. npm的更新: $ sudo npm in ...
- sublime-text3插件安装
sublime-text3和sublime-text2一样安装插件前都需要先安装,Package control ,然而安装Package control的代码和sublime-text2又不相同.如 ...
- ACM - ICPC World Finals 2013 B Hey, Better Bettor
原题下载:http://icpc.baylor.edu/download/worldfinals/problems/icpc2013.pdf 这题真心的麻烦……程序不长但是推导过程比较复杂,不太好想 ...
- LA 5846 (计数) Neon Sign
从反面考虑,统计非单色三角形的个数. 如果从一个点出发两条不同颜色的边,那么这三个点一定构成一个非单色三角形. 枚举一个顶点,统计从这个点出发的红边的个数a[i]和蓝边的个数n - 1 - a[i], ...
- rsync不存在用户处理CPU消耗拒绝服务漏洞
受影响产品: rsync 3.1.0 漏洞描述: CVE ID:CVE-2014-2855 rsync是一款文件同步管理软件. rsync处理不存在用户时存在安全漏洞,可消耗大量CPU资源,造成拒绝服 ...
- Jqgrid demo-史上最强大,没有之一
为了大家能够更好的学习和使用Jqgrid网格插件,我决定用Strtus2+Spring+hibernate+Jquery+Jqgrid实现一个Jqgrid网格插件的demo.当然官方网 ...
- BZOJ2229: [Zjoi2011]最小割
题解: 真是一道神题!!! 大家还是围观JZP的题解吧(网址找不到了...) 代码: #include<cstdio> #include<cstdlib> #include&l ...
- Java知识点:琐碎知识点(2)
49个关键字一览 abstract default if private this boolean do implements protected throw break double import ...
- chrome 远程调试(转)
http://www.tuicool.com/articles/ZJfeAzi 由于 appspot.com被墙,一般调试不成功. 随着智能手机的普及,移动设备的浏览器功能越来越强大,我们用手机上网时 ...