博客
关于我
【模板】有向图tarjan
阅读量:171 次
发布时间:2019-02-28

本文共 714 字,大约阅读时间需要 2 分钟。

#include 
using namespace std;const int N = 10005, M = 50005;vector
son[N];int dfn[N], low[N], num, s[N], out[N], top, cnt;int scc[N];int sz[N], n, m;void tarjan(int u) { low[u] = dfn[u] = ++num; s[++top] = u; for (int i = 0; i < son[u].size(); ++i) { if (dfn[son[u][i]] == 0) { tarjan(son[u][i]); low[u] = min(low[u], low[son[u][i]]); } else if (dfn[son[u][i]] < dfn[u]) { low[u] = min(low[u], dfn[son[u][i]]); } } if (low[u] == dfn[u]) { ++cnt; scc[cnt] = top; sz[cnt] = top - s[0] + 1; for (int v = s[top]; top-- < s[0]; v = s[--top]) { out[v] = cnt; sz[cnt]--; } }}

转载地址:http://iawn.baihongyu.com/

你可能感兴趣的文章
POJ 3988 Selecting courses
查看>>
POJ 4020 NEERC John's inversion 贪心+归并求逆序对
查看>>
poj 4044 Score Sequence(暴力)
查看>>
POJ 基础数据结构
查看>>
POJ 题目3020 Antenna Placement(二分图)
查看>>
Poj(1797) Dijkstra对松弛条件的变形
查看>>
SpringBoot为什么不需要xml配置文件?
查看>>
POJ--2391--Ombrophobic Bovines【分割点+Floyd+Dinic优化+二分法答案】最大网络流量
查看>>
Qt笔记——SQLite初探QSqlDatabase QSqlQuery
查看>>
POJ-1163-The Triangle
查看>>
POJ-Fence Repair 哈夫曼树
查看>>
poj1061 - 同余方程,二元一次不定方程
查看>>
Qt笔记——SQLite再探
查看>>
poj1068Parencodings
查看>>
poj1182(带权并查集)
查看>>
POJ1182(带权并查集)
查看>>
Qt笔记——Qt初探、PyQt5和Qt5
查看>>
poj1190生日蛋糕
查看>>
POJ1218 HDU1337 ZOJ1350 UVALive2557 THE DRUNK JAILER
查看>>
poj1222 EXTENDED LIGHTS OUT(gauss)
查看>>