随笔分类 -  图论--tarjan

摘要:题:https://www.luogu.com.cn/problem/P4244 分析:定义f[i]表示dfs过程中 i 节点到子树叶子节点的最大距离; 考虑俩种边的俩种情况,【1】假设枚举边为树边(桥),那么对答案的更新则为f[u]+f[v]+1,表示在枚举v之前的最大叶子节点距离和当前v节点到叶 阅读全文
posted @ 2020-08-20 09:51 starve_to_death 阅读(130) 评论(0) 推荐(0)
摘要:题:http://acm.hdu.edu.cn/showproblem.php?pid=4635 题意:给n个点m条边的有向图,问最多还能添加多少条边,让此图还不能形成强连通图; 分析:tarjan缩点后,我们知道要是点双的个数是1那么肯定不符合条件,就直接输出-1; 那么剩下的情况就是,我们挑出一 阅读全文
posted @ 2020-03-06 17:22 starve_to_death 阅读(136) 评论(0) 推荐(0)
摘要:洛谷2661 https://www.luogu.org/problemnew/show/P2661 分析:求缩点后成环中,环大小最小的size #include<bits/stdc++.h> using namespace std; const int M=2e5+5; vector<int>e[ 阅读全文
posted @ 2019-07-16 08:38 starve_to_death 阅读(189) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=3694 给一副图,(可能有环,但联通)然后给定q次询问,每次询问的u,v是要加上去的边,问加上去后,若图的边联通度还是1时,有多少条桥 利用并查集缩点,先用tarjan求出总的桥的数量; 利用tarjan中的dfn来找每次u,v的LCA,u到v路 阅读全文
posted @ 2019-07-09 13:49 starve_to_death 阅读(177) 评论(0) 推荐(0)
摘要:概念: 边双连通分量:不存在桥的无向图为边双连通图, 极大边双连通图为边双连通分量(以点存) #include<bits/stdc++.h> #define N 100010 using namespace std; struct node{ int v,nextt; }e[N<<1]; //c[x 阅读全文
posted @ 2019-06-02 21:02 starve_to_death 阅读(196) 评论(0) 推荐(0)
摘要:割点: void tarjan(int u){ dfn[u]=low[u]=++cnt; int flag=0; for(int i=head[u];~i;i=e[i].nextt){ int v=e[i].v; if(!dfn[v]){ tarjan(v); low[u]=min(low[u],l 阅读全文
posted @ 2019-05-31 17:34 starve_to_death 阅读(128) 评论(0) 推荐(0)
摘要:学习资料:https://www.cnblogs.com/shadowland/p/5872257.html 板子: void tarjan(int u){ dfn[u]=low[u]=++cnt; sta[++top]=u; vis[u]=true; for(int i=0;i<g[u].size 阅读全文
posted @ 2019-05-29 20:56 starve_to_death 阅读(171) 评论(0) 推荐(0)