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).

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <list>
#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[maxn*maxn], y[maxn*maxn];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;
}

转载于:https://www.cnblogs.com/Sunshine-tcf/p/5781411.html

UVALive 7456 Least Crucial Node (并查集)相关推荐

  1. UVALive 7456 Least Crucial Node

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  2. 【割点 dfs】UVALive - 7456 Least Crucial Node

    Problem Description 给你n,s,m分别代表n个点,s为特殊点,m条边.让你求去掉那个点?使得其他点不能到达s点的点最多.如果存在割点,一样多的.输出编号最小的. 思路: 割点的条件 ...

  3. UVALive - 7456 Least Crucial Node ( dfs + set )

    直接暴力求解,枚举每个点, dfs 求解对后面影响的点的个数 #include <iostream> #include <cstdio> #include <string ...

  4. UVALive Problem 7456 Least Crucial Node——Regionals 2015 :: Asia - Taipei

    此文章可以使用目录功能哟↑(点击上方[+])  UVALive Problem 7456 Least Crucial Node Accept: 0    Submit: 0 Time Limit: 3 ...

  5. UVALive 4035 - Undetectable Tour(并查集)

    题意:给定一个 N * N(3 <= N <= 10000)的矩形区域,左下角为(0,0),右上角为(N,N),现在要从左下角走到右上角,但是有 k(k <= 100)个监视器,每个 ...

  6. LA 7456 Least Crucial Node

    题意:有一个联通图G(V,E), |V| <= 100,其中一个vertex是源点,即sink,由sink沿图向其他点发送信息.当你disable了一个点(非sink),阻断了通过该点的信息传输 ...

  7. 牛客多校8 - All-Star Game(线段树分治+并查集按秩合并的撤销操作)

    题目链接:点击查看 题目大意:有 n 个球员和 m 个球迷,一个球员可能是多个球迷的粉丝,需要选择最少的球员进行比赛,使得所有的球迷都愿意观看(对于每个球迷来说,都有至少一个其喜欢的球员入选比赛) 对 ...

  8. HDU1811 Rank of Tetris 拓扑排序+并查集 OR 差分约束最短路+并查集

    题目链接 题意:就是给你一堆关系,看能不能排出个确定的顺序 做法: 1. 拓扑排序+并查集 应该很容易想到的一种思路,大于小于建立单向边.对于相等的呢,就把他们缩成一个点.就用并查集缩成一个点就行了 ...

  9. HDU 2586 How far away ? LCA ---tanjar+并查集 离线算法

    tanjar算法离线求LCA的思想主要是利用并查集的思想. 求距离的话就是d[start[i]]+end[en[i]]-2*d[lca[i]]; 首先从根节点dfs,在深度遍历的回溯的过程中不断的更新 ...

最新文章

  1. VAE(Variational Autoencoder)的原理
  2. Cacti/Nagios监控系统应用场景
  3. Matlab处理JSON数据
  4. 全球计算机与工程学科排名:MIT夺冠 中国23所高校上榜
  5. R与量化(part1)--量化概述
  6. 目标检测——域适应的学习笔记
  7. 软件测试团队队名,电子设计大赛队名
  8. XenApp简单部署
  9. jboot websocket的使用
  10. 【GUI制作】tkinter-一款跨平台的简易GUI库
  11. Propensity Score Matching
  12. linux ping等待时间,linux ping命令详解
  13. 今日头条推荐算法详解(PDF下载)
  14. web开发浏览器缓存问题之Google浏览器缓存清理
  15. 【最近抖音上元宇宙虚拟项目七国争霸,直播互动游戏源码解析】
  16. word文档的生成以及echarts图片的插入
  17. Html转义字符表详细记录
  18. 介绍-FreeMarker
  19. Visio更改图形块的内边距
  20. 【公告 | 阿布扎比全球市场为中东和北非地区推出加密资产框架】

热门文章

  1. python一入深似海-模块化编程-钢铁侠战甲(二)
  2. 美容院前台收银软件用什么好?
  3. 古学今用——不要那么直白了
  4. 机器学习(9)--决策树和随机森林
  5. 十步会用IOCOMP–iplotx控件
  6. 在数据库创建时创建OMF(Oracle Managed Files,Oracle管理的文件)
  7. CSS 网页弹出微信二维码
  8. 使用Sinc卷积从原始音频数据进行轻量级的端到端语音识别
  9. java爬虫爬取B站弹幕
  10. Microsoft Visual C++ Runtime Library Runtime Error的一个解决方法