tarjan求强连通分量(模板)
https://www.luogu.org/problem/P2341 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxn=50010; int pre[maxn],other[maxn],last[maxn],l; int n,m; int dfn[maxn],low[maxn],ans[maxn],st[maxn],belong[maxn],cnt,top,qw; //dfn->dfs序,low是点上非树边指向的点(拥有最小的dfs序 ),st是一个栈,记录环上的点,belong是点所属于的环 void add(int x,int y) { l++; pre[l]=last[x]; last[x]=l; other[l]=y; } int ru[maxn],chu[maxn];//入度,出度 void dfs(int x) { dfn[x]=low[x]=++cnt;//可以知道每个点都指向自己(low) ru[x]=1; st[++top]=x; for(int p=last[x];p;p=pre[p]) { int v=other[p]; if(!dfn[v]) { dfs(v);//此时v的信息已经更新完毕 low[x]=min(low[x]