题目链接: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. JS绑定事件处理函数及处理流程

    一.事件绑定的几种方式: 1.1 ele.on+“事件名“:如div.onclick = function(event){ }; 1.1.1这种方式兼容性非常好,但一个元素的同一个事件上只能绑定一个处 ...

  2. K3/cloud执行计划插件示例

    public class AutoCheckInventory : IScheduleService { /// <summary>        /// 实际运行的Run 方法      ...

  3. Wannafly Camp 2020 Day 6N. 合并!

    #include <bits/stdc++.h> using namespace std; int n,a[2005]; int main() { long long ans=0; cin ...

  4. linux - 删除软件包

    # 参数e的作用是使rpm进入卸载模式,对名为[package name]的软件包进行卸载 rpm -e [package name] # 由于系统中各个软件包之间相互有依赖关系,使用-nodeps忽 ...

  5. 二分-E - Rikka with Mutex

    E - Rikka with Mutex Sometimes, technical terms implicate some life philosophy. Mutex is one of them ...

  6. HTML /和./的区别 - Web开发

    "/"访问根目录 例1 https://www.cnblogs.com/test 里有 <a href="/Edsuns"></a> 则 ...

  7. 模块一:shell 脚本基础

    一.shell脚本介绍 (一)脚本案例及介绍: #!/bin/bash LOG_DIR=/var/log ROOT_UID=0 if ["$UID -ne "$ROOT_UID&q ...

  8. soundtouch change pitch matlab implementation

    function output = changePitch(input, pitchInSemitones) % one octave is 12 semitones octave = pitchIn ...

  9. 从原理到方案,一步步讲解web移动端实现自适应等比缩放

    前言 在移动端做自适应,我们常用的有媒体查询,rem ,em,宽度百分比这几种方案.但是都各有其缺点. 首先拿媒体查询来说,在某一个宽度区间内只能使用一种样式,为了适应不同屏幕要,css的代码量就会增 ...

  10. codeblocks汉化

    1.- 汉化包 腾讯微云 2.首先打开codeblocks安装文件夹,如:D:\CodeBlocks\share\CodeBlocks\locale\zh_CN,注意:zh_CN文件夹需自行创建 3. ...