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 bamboo12345 @ 2023-06-11 20:53:22
@Baoziawa_int32768 先学一下边双吧这个做法部队的
by RP_INT_MAX @ 2023-06-11 20:53:57
Tarjon.jpg(
by fjy666 @ 2023-06-11 20:57:50
It's Tarjan.
by Milthm @ 2023-06-11 21:03:41
《Tarjon》
by Baoziawa_int32768 @ 2023-06-11 23:01:53
@bamboo123 这不就是边双吗??????????????????????
by Baoziawa_int32768 @ 2023-06-11 23:02:28
@RP_INT_MAX @fjy666 @songjiahao 笔误了笔误了笔误了orz
by bamboo12345 @ 2023-06-11 23:03:37
@Baoziawa_int32768 额学习一下你就知道你这啥也不是(
by Baoziawa_int32768 @ 2023-06-11 23:07:12
@bamboo123 ????????我照着模板写的啊
by Baoziawa_int32768 @ 2023-06-11 23:08:22
@bamboo123 而且dfs的过程应该问题都不大 我TM95pts
by bamboo12345 @ 2023-06-11 23:09:52
@Baoziawa_int32768 简简单单轻松hack:
2 2
1 2
1 2