题目链接:https://vjudge.net/problem/UVA-796

题目:裸的求桥,按第一个元素升序输出即可。

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define pb push_back
#define fi first
#define se second const int N = (int)1e3+;
int n,tot,tim;
int head[N],dfn[N],low[N];
struct node{
int to;
int nxt;
}e[N*N];
vector<pair<int,int> > cut; void init(){
for(int i = ; i <= n; ++i){
head[i] = -;
dfn[i] = ;
}
tim = tot = ;
} inline void add(int u,int v){
e[tot].to = v;
e[tot].nxt = head[u];
head[u] = tot++;
} void tarjan(int now,int pre){
dfn[now] = low[now] = ++tim;
int to;
for(int o = head[now]; ~o; o = e[o].nxt){
to = e[o].to;
if(to == pre) continue;//双向边的判断
if(!dfn[to]){
tarjan(to,now);
low[now] = min(low[now],low[to]);
//桥的条件
if(dfn[now] < low[to]) cut.pb(make_pair(min(now,to),max(now,to)));
}
else if(low[now] > dfn[to]) low[now] = dfn[to];
}
} void _ans(){ int ans = cut.size();
sort(cut.begin(),cut.end());
printf("%d critical links\n",ans);
for(int i = ; i < ans; ++i) printf("%d - %d\n",cut[i].fi,cut[i].se);
printf("\n");
cut.clear();
} int main(){ int u,v,m;
while(~scanf("%d",&n)){
init(); for(int i = ; i < n; ++i){
scanf("%d (%d)",&u,&m);
for(int j = ; j < m; ++j){
scanf("%d",&v);
add(u,v);
}
} for(int i = ; i < n; ++i) if(!dfn[i]) tarjan(i,i);
_ans();
} return ;
}

kuangbin专题 专题九 连通图 Critical Links UVA - 796的更多相关文章

  1. [kuangbin带你飞]专题九 连通图C - Critical Links UVA - 796

    这道题就是要求桥的个数. 那么桥相应的也有判定的定理: 在和u相邻的节点中,存在一个节点是最小的时间戳都比 当前u的访问次序要大,也就是说这个点是只能通过果u到达,那么 他们之间相邻的边就是的桥 #i ...

  2. (连通图 模板题 无向图求桥)Critical Links -- UVA -- 796

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  3. C - Critical Links - uva 796(求桥)

    题意:有一些网络通过一些线路连接,求关键的连接,也就是桥,如果删除这个链接那么会产生两个子树 分析:注意一下图不是连通图即可 ************************************* ...

  4. [kuangbin带你飞]专题九 连通图B - Network UVA - 315

    判断割点的性质: 如果点y满足 low[y]>=dfn[x] 且不是根节点 或者是根节点,满足上述式子的有两个及其以上. 就是割点 如果是起点,那么至少需要两个子节点满足上述条件,因为它是根节点 ...

  5. [kuangbin带你飞]专题九 连通图

        ID Origin Title   76 / 163 Problem A POJ 1236 Network of Schools   59 / 177 Problem B UVA 315 Ne ...

  6. 「kuangbin带你飞」专题十九 矩阵

    layout: post title: 「kuangbin带你飞」专题十九 矩阵 author: "luowentaoaa" catalog: true tags: mathjax ...

  7. 给自己的小练习19-[kuangbin带你飞]专题九连通图

    没有写题解.补一波 Network of Schools 问题1:求有向图中入度为0的点个数 问题2:使得整个图变成一个联通分量 问题1直接缩点统计 问题2=max(入度为0的点,出度为0的点),注意 ...

  8. uva 796 Critical Links(无向图求桥)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  9. UVA 796 Critical Links(模板题)(无向图求桥)

    <题目链接> 题目大意: 无向连通图求桥,并将桥按顺序输出. 解题分析: 无向图求桥的模板题,下面用了kuangbin的模板. #include <cstdio> #inclu ...

随机推荐

  1. unity中ContentSizeFitter刷新不及时的问题

    ContentSizeFitter,自适应宽高脚本要在下一帧的时候才会适应宽高.如果想立即生效,可以调用 LayoutRebuilder.ForceRebuildLayoutImmediate(rec ...

  2. Leetcode Week2 Two Sum

    Question Given an array of integers, return indices of the two numbers such that they add up to a sp ...

  3. ABC155 D pair 边界处理取整

    ABC155 D pair 取整坑点 思路 很常见的一道题,二分找答案,然后看这个答案排rank?,排rank?用二分继续找一遍二分套二分即可,就是边界比较烦,老年人写的心情烦躁 老年人被取整坑的几天 ...

  4. [AtCoder Code Festival 2017 QualB D/At3575] 101 to 010 - dp

    [Atcoder Code Festival 2017 QualB/At3575] 101 to 010 有一个01序列,每次可以选出一个101,使其变成010,问最优策略下能操作几次? 考虑像 11 ...

  5. hive创建表时报错

    这是因为mysql字符集的原因.修改mysql的字符集. mysql> alter database hive character set latin1; 参考博客:https://blog.c ...

  6. Selenium3+python自动化011-unittest生成测试报告(HTMLTestRunner)

    批量执行完用例后,生成的测试报告是文本形式的,不够直观,为了更好的展示测试报告,最好是生成HTML格式的. unittest里面是不能生成html格式报告的,需要导入一个第三方的模块:HTMLTest ...

  7. C++——动态内存分配1

    9.动态内存分配  new 类型名T(初值列表) 其功能是在程序执行期间申请用于存放T类型对象的内存空间,并依初值列表赋以初值,结果值:成功则T类型的指针,指向新分配的内存:失败则为0(null).若 ...

  8. jdk8-》allMatch、anyMatch、max、min函数

    allMatch函数: 检查是否匹配所有元素,只有全部符合才返回true boolean flag = list.stream().allMatch(obj->obj.length()>5 ...

  9. linux命令 EOF

    在shell脚本中,通常将EOF与 << 结合使用,表示后续的输入作为子命令或子Shell的输入,直到遇到EOF为止,再返回到主Shell. EOF只是一个分界符,当然也可以用abcde替 ...

  10. Codeforces Round #614 (Div. 2) A-E简要题解

    链接:https://codeforces.com/contest/1293 A. ConneR and the A.R.C. Markland-N 题意:略 思路:上下枚举1000次扫一遍,比较一下 ...