Baoziawa_int32768 @ 2023-06-11 20:49:13
RT,只要求输出边双连通分量数量
#include<bits/stdc++.h>
using namespace std;
int m,n,a,b,ans,low[500000+10],dfn[500000+10],cnt,belong[500000+10];
vector<int>V[500000+10];
stack<int>S;
void tarjon(int u,int f){
S.push(u);
dfn[u]=low[u]=++cnt;
for(int i=0;i<V[u].size();i++){
int v=V[u][i];
if(v==f)continue;
if(!dfn[v]){
tarjon(v,u);
low[u]=min(low[u],low[v]);
}else{
low[u]=min(low[u],dfn[v]);
}
}
if(dfn[u]==low[u]&&!belong[S.top()]){
ans++;
int pos;
do{
pos=S.top();S.pop();
belong[pos]=ans;
}while(pos!=u);
}
}
int main(){
cin>>n>>m;
for(int i=1;i<=m;i++){
cin>>a>>b;
V[a].push_back(b);
V[b].push_back(a);
}
for(int i=1;i<=n;i++)if(!dfn[i])tarjon(i,0);
cout<<ans<<endl;
}
by Baoziawa_int32768 @ 2023-06-11 23:14:20
@bamboo123 你这啥玩意 你建两条相同的边是什么意思…
by bamboo12345 @ 2023-06-11 23:15:26
@Baoziawa_int32768 没说没有重边吧是吧
by Baoziawa_int32768 @ 2023-06-11 23:16:28
@bamboo123 彳亍 但是 什么叫这不是Tarjan(
by Baoziawa_int32768 @ 2023-06-11 23:17:17
@Baoziawa_int32768 呸 边双
by bamboo12345 @ 2023-06-12 17:00:33
@Baoziawa_int32768 就是说你这个是介于边双和点双之间的一个玩意儿