题意:有一个联通图G(V,E), |V| <= 100,其中一个vertex是源点,即sink,由sink沿图向其他点发送信息。当你disable了一个点(非sink),阻断了通过该点的信息传输,会导致一些点无法收到信息;一个点被禁用后,导致无法收到信息点数越多,就越crucial。让你求出最crucial而且数字编号最小的点。

方法:DFS

图非常的小,边数最多1e4条,我们只需循环每一个非sink的点,关闭它,然后从sink 开始dfs,求联通分量的大小。

这样做的time complexity是O(n*(|V|+|E|)), 一个case的计算量在1e6左右,不会超过10个testcase,可行。

Code:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>
#include <list>
#include <deque>
#include <map>
#include <queue>
#include <fstream>
#include <cassert>#include <cmath>
#include <sstream>
#include <time.h>
#include <complex>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define DFOR(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define rep(i,n) FOR(i,0,n)
#define repn(i,n) FORN(i,1,n)
#define drep(i,n) DFOR(i,n-1,0)
#define drepn(i,n) DFOR(i,n,1)
#define MAX(a,b) a = Max(a,b)
#define MIN(a,b) a = Min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define Reset(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(all(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)
#define forever for(;;)
#define PINF 1000000000000
#define newline '\n'#define test if(1)cout
using namespace std;using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<double,double> dd;
typedef pair<char,char> cc;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l4;
const double pi = acos(-1.0);const int maxn = 101;
int n, m, sink;
vector<int> g[maxn];
bitset<maxn> vis;
void dfs(int cur)
{vis[cur] = true;for (auto nxt : g[cur]){if (!vis[nxt]){dfs(nxt);}}
}int main()
{while (cin >> n && n){repn(i, n)  g[i].clear();cin >> sink >> m;rep(i, m){int u, v;   cin >> u >> v;g[u].pb(v);g[v].pb(u);}int ans = -1;int cnt = n+1;repn(i, n){if (i == sink)  continue;vis.reset();vis[i] = true;dfs(sink);int temp = vis.count();if (temp == n)  continue;if (cnt > temp){ans = i;cnt = temp;}}cout << ans << newline;}
}

LA 7456 Least Crucial Node相关推荐

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

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

  2. UVALive 7456 Least Crucial Node (并查集)

    Least Crucial Node 题目链接: http://acm.hust.edu.cn/vjudge/contest/127401#problem/C Description http://7 ...

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

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

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

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

  5. UVALive 7456 Least Crucial Node

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

  6. Least Crucial Node UVALive - 7456

    AC代码(找与k联通的点最少的那个node, dfs) Select Code #include <iostream> #include <bits/stdc++.h> #de ...

  7. Least Crucial Node UVALive - 7456 【】

    题目要求:求联通图   序号最小的最大割点. 解决方案: 枚举每一个点(除了起点),每一次从头开始搜. 比较出 去掉哪个点 时 能连的最少 一些新stl 知识点 bitset : 百度百科 auto ...

  8. Windows系统下nodejs安装及配置

    关于nodejs中文站,眼下活跃度最好的知识站应该是http://www.cnodejs.org/ ,而http://cnodejs.org/则活跃度较低.Express.js是nodejs的一个MV ...

  9. 数据结构之链表创建一元多项式,求一元多项式之和

    数据结构之链表创建一元多项式,求一元多项式之和 前言 对于一元多项式,我们完全可以利用线性表P(a0,a1,a2,-,an)表示,这样的线性表在求两个多项式相加等操作时确实简单,但是多于如下的多项式: ...

最新文章

  1. Upgrade after a crash is not supported. The redo log was created with Maria的解决办法
  2. cocos2d-x 3.x 场景切换特效大集合
  3. java等待欢迎界面_android welcome欢迎界面3秒后自动跳转
  4. Scala基础教程(二):数据类型、变量
  5. unittest单元测试框架总结
  6. Java基础笔记 – 增强的for循环For each循环 自动装箱拆箱 可变参数
  7. 1499元!魅族Watch“天青”配色正式首销:与手机完全互联互通
  8. WIFI测试APP(华为、华三、锐捷)
  9. 深度学习GPU最全对比,到底谁才是性价比之王?
  10. 128g固态加1linux分区,应该如何使用128G加1T机械硬盘?要不要分盘?
  11. 服务器kvm切换器维修,KVM多电脑切换器常见故障排查及处理方法
  12. html 怎么布局ui,移动端UI快速布局解决方案AUI
  13. mysql强制修改root密码
  14. 在Etherscan上自动验证Truffle智能合约
  15. 上传照片显示服务器繁忙怎么回事,解决WordPress上传图片“图像后期处理失败,可能是服务器忙或没有足够的资源”问题...
  16. LTE物理层概述(4)-- LTE时间帧及资源块
  17. linux 修改xt_recent参数 ip_list_tot ip_pkt_list_tot
  18. Spark 是否真的比 MapReduce 技高一筹
  19. 超市商品管理系统(c语言)
  20. 【学习笔记】矩阵运算入门

热门文章

  1. Windows官网直接下载正版操作系统方法
  2. vue使用provide / inject 组合刷新页面+单独组件刷新
  3. NLPCC20@基于图注意网络的句子成分感知细粒度情感分析模型SCAN
  4. N-Tiers开发方式(为何使用COM+组件的撰写商业逻辑层)
  5. 递归陷入死循环的判断方法与解决措施(java代码)
  6. oracle omf管理,论OMF管理文件的重要性
  7. 单片机/C语言浮点型数据转换为字符串方法
  8. 形式语言与自动机 Part.6 图灵机
  9. iphone se 一代 不完美越狱 14.6 视频壁纸教程(踩坑笔记)
  10. 【转载】UEBA架构设计之路