This commit is contained in:
parent
3a00516eff
commit
78b4006392
|
@ -0,0 +1,20 @@
|
|||
void tarjan(int u, int father) {
|
||||
vis[u] = true;
|
||||
low[u] = dfn[u] = ++cnt;
|
||||
int child = 0;
|
||||
for (auto v : edge[u]) {
|
||||
if (!vis[v]) {
|
||||
child++;
|
||||
tarjan(v, u);
|
||||
low[u] = min(low[u], low[v]);
|
||||
if (father != u && low[v] >= dfn[u] && !flag[u]) {
|
||||
flag[u] = true;
|
||||
res++;
|
||||
}
|
||||
} else if (v != father) low[u] = min(low[u], dfn[v]);
|
||||
}
|
||||
if (father == u && child >= 2 && !flag[u]) {
|
||||
flag[u] = true;
|
||||
res++;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
// st = stack, vis = visited, br = branch(result)
|
||||
|
||||
constexpr int MAXN=1e5+10;
|
||||
int dfn[MAXN],low[MAXN],st[MAXN],vis[MAXN],br[MAXN];
|
||||
int n,cnt,stn,scn;
|
||||
vector<int>ch[MAXN];
|
||||
void tarjan(int v){
|
||||
dfn[v]=low[v]=++cnt;
|
||||
st[stn++]=v;
|
||||
vis[v]=1;
|
||||
for(const auto&u:ch[v])
|
||||
if(!dfn[u])tarjan(u),low[v]=min(low[v],low[u]);
|
||||
else if(vis[u])low[v]=min(low[v],dfn[u]);
|
||||
if(dfn[v]==low[v]){
|
||||
++scn;
|
||||
int u;
|
||||
do u=st[--stn],vis[u]=0,br[u]=scn; while(u!=v);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue