这是 DFS 系列的第一篇 。

首先给出一个重要的定理。该定理来自《算法导论》。

An undirected graph may entail some ambiguity in how we classify edges, since $(u,v)$ and $(v,u)$ are really the same edge. In such a case, we classify the edge according to whichever of $(u,v)$ or $(v,u)$ the search encounters first.

Introduction to Algorithm 3rd edition p.610

Theorem 22.10
In a depth-first search of an undirected graph $G$, every edge of $G$ is either a tree edge or a back edge.

Proof  Let $(u, v)$ be an arbitrary edge of $G$, and suppose without loss of generality that $u.d < v.d$. Then the search must discover and finish $v$ before it finishes $u$ (while $u$ is gray), since $v$ is on $u$’s adjacency list. If the first time that the search explores edge $(u, v)$, it is in the direction from $u$ to $v$, then $v$ is undiscovered (white) until that time, for otherwise the search would have explored this edge already in the direction from $v$ to $u$. Thus, $(u, v)$ becomes a tree edge. If the search explores $(u, v)$ first in the direction from $v$ to $u$, then $(u, v)$ is a back edge, since $u$ is still gray at the time the edge is first explored.

low 值大概是 Robert Tarjan 在论文 Depth-first search and linear graph algorithms  SIAM J. Comput. Vol. 1, No. 2, June 1972 给出的概念。

(p.150)"..., LOWPT(v) is the smallest vertex reachable from v by traversing zero or more tree arcs followed by at most one frond."

代码如下

 #define set0(a) memset(a, 0, sizeof(a))
typedef vector<int> vi;
vi G[MAX_N];
int ts; //time stamp
int dfn[MAX_N], low[MAX_N];
void dfs(int u, int f){
dfn[u]=low[u]=++ts;
for(int i=; i<G[u].size(); i++){
int &v=G[u][i];
if(!dfn[v]){ //tree edge
dfs(v, u);
low[u]=min(low[u], low[v]);
}
else if(dfn[v]<dfn[u]&&v!=f){ //back edge
low[u]=min(low[u], dfn[v]);
}
}
}
void solve(int N){
set0(dfn);
ts=;
for(int i=; i<=N; i++)
if(!dfn[i]) dfs(i, i);
}

连通性1 求无向图的low值的更多相关文章

  1. Hdu 4738【tanjan求无向图的桥】割边判定定理 dfn[x] < low[y]

    题目: 曹操在长江上建立了一些点,点之间有一些边连着.如果这些点构成的无向图变成了连通图,那么曹操就无敌了.刘备为了防止曹操变得无敌,就打算去摧毁连接曹操的点的桥.但是诸葛亮把所有炸弹都带走了,只留下 ...

  2. 【求无向图的桥,有重边】ZOJ - 2588 Burning Bridges

    模板题——求割点与桥 题意,要使一个无向图不连通,输出必定要删掉的边的数量及其编号.求桥的裸题,可拿来练手. 套模板的时候注意本题两节点之间可能有多条边,而模板是不判重边的,所以直接套模板的话,会将重 ...

  3. [Tarjan系列] Tarjan算法求无向图的桥和割点

    RobertTarjan真的是一个传说级的大人物. 他发明的LCT,SplayTree这些数据结构真的给我带来了诸多便利,各种动态图论题都可以用LCT解决. 而且,Tarjan并不只发明了LCT,他对 ...

  4. FZU 2090 旅行社的烦恼 floyd 求无向图最小环

    题目链接:旅行社的烦恼 题意是求无向图的最小环,如果有的话,输出个数,并且输出权值. 刚刚补了一发floyd 动态规划原理,用了滑动数组的思想.所以,这个题就是floyd思想的变形.在k从1到n的过程 ...

  5. Tarjan求无向图割点、桥详解

    tarjan算法--求无向图的割点和桥   一.基本概念 1.桥:是存在于无向图中的这样的一条边,如果去掉这一条边,那么整张无向图会分为两部分,这样的一条边称为桥无向连通图中,如果删除某边后,图变成不 ...

  6. tarkjan求无向图割点模板

    #include<bits/stdc++.h> using namespace std; typedef long long ll; int n,m; ; ; struct node { ...

  7. [Tarjan系列] Tarjan算法求无向图的双连通分量

    这篇介绍如何用Tarjan算法求Double Connected Component,即双连通分量. 双联通分量包括点双连通分量v-DCC和边连通分量e-DCC. 若一张无向连通图不存在割点,则称它为 ...

  8. 求 无向图的割点和桥,Tarjan模板

    /* 求 无向图的割点和桥 可以找出割点和桥,求删掉每个点后增加的连通块. 需要注意重边的处理,可以先用矩阵存,再转邻接表,或者进行判重 */ const int MAXN = 10010; cons ...

  9. tarjan算法求无向图的桥、边双连通分量并缩点

    // tarjan算法求无向图的桥.边双连通分量并缩点 #include<iostream> #include<cstdio> #include<cstring> ...

随机推荐

  1. maya获取邻接顶点的一个问题

    maya网格数据结构允许"非流形"的存在,于是,这种数据结构无法按顺序给出一个点的邻接顶点. 于是,MItMeshVertex::getConnectedVertices函数返回的 ...

  2. javascript设置网页刷新或者重新加载后滚动条的位置不变

    有个同事说再javascript中你可以做任何你想做的事情,当时觉得不以为然,今天遇到个问题,就是页面重新加载后总是回到页面的顶部,如果客户只想看到他想看到的部分是怎么变化的,这个体验就好了.原本想象 ...

  3. MySQL基础 - 如何系统地学习数据库?

    对于数据库的认知,除了大学的时候上过数据库这门课,留下的印象大概就是几条SQL语句一些模棱两可的基本概念,直到工作后面临使用场景才发现数据库的重要性.故归纳总结一下自己的数据库学习之路. 学习资源: ...

  4. Angular权威指南学习笔记

    第一章.        初识Angular--Angular是MVW的Js框架. 第二章.        数据绑定--ViewModel中不仅可以含有变量,还可以还有事件.可以通过事件来控制变量的值改 ...

  5. GEOS库学习之三:空间关系、DE-9IM和谓词

    要判断两个多边形的关系,实际上属于几何图形空间关系判断.几何图形并不只有多边形一种,它包括点.线.面构成的任何图形,两两之间相互关系也有很多种,因此空间关系非常复杂.根据前人的研究,总结出了DE-9I ...

  6. jquery-lazyload延迟加载图片 及 加载顺序 bug 修复

    jquery-lazyload延迟加载图片   代码修改片段 function update() { var counter = 0; /**fix by weiyj start***/ elemen ...

  7. 20135208 20135212 LINUX第一次实验报告

    北京电子科技学院(BESTI) 实     验    报     告 课程:信息安全系统设计基础                     班级: 201352 姓名:池彬宁 贺邦 学号:2013521 ...

  8. 创建Spring容器

    对于使用Spring的web应用,无须手动创建Spring容器,而是通过配置文件,声明式的创建Spring容器.在Web应用中,创建Spring容器有如下两种方式:1.直接在web.xml文件中配置: ...

  9. ios——MPMoviePlayerController截取视频缩略图 播放视频又可以截取视频缩略图

    #import <AVKit/AVKit.h>#import <MediaPlayer/MediaPlayer.h>#import "ViewController.h ...

  10. CUDA编程学习(二)

    将数据加载到GPU后,如何在grid下的block进行并行计算(一个grid包含多个block) /****How do we run code in parallel on the device** ...