版本比较
【模板】图论
正文
增加 88 行删除 0 行
804 行未改动全部展开805806807808804 行未改动全部展开return 0;}```804 行未改动全部展开805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896804 行未改动全部展开return 0;}```### 边双连通分量```cpp line-numbers#include<bits/stdc++.h>#define loveFurina ios::sync_with_stdio(0)#define loveFocalors cin.tie(0),cout.tie(0)using namespace std;char buf[1<<20],*p1=buf,*p2=buf;inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++;}inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9')x=x*10+(ch-'0'),ch=getchar();return x*f;}inline void write(int x,int typ){if(x<0)putchar('-'),x=-x;if(x<10)putchar(x+'0');else write(x/10,0),putchar(x%10+'0');if(typ==0) return;else if(typ==1) putchar(' ');else putchar('\n');}const int N=5e5+5,M=4e6+5,MN=4e6+5;struct node{int to,nxt;}edge[M];int head[N];int top;int s[M],ans,low[N],dfn[N],idx;int n,m,tot;int dbf[MN],dcl[N],pos;inline void add(int x,int y){edge[++tot].to=y;edge[tot].nxt=head[x];head[x]=tot;return;}inline void tarjan(int x,int fa){low[x]=dfn[x]=++idx;s[++top]=x;for(int i=head[x];i;i=edge[i].nxt){int u=edge[i].to;if(!dfn[u]){tarjan(u,i);low[x]=min(low[x],low[u]);}else if(i!=(fa^1)){low[x]=min(low[x],dfn[u]);}}if(dfn[x]==low[x]){ans++;int cur;do{cur=s[top--];dbf[++pos]=cur;dcl[ans]++;}while(cur!=x);}}inline void solve(){n=read(),m=read();tot=1;for(int i=1;i<=m;i++){int x=read(),y=read();add(x,y),add(y,x);}for(int i=1;i<=n;i++){if(!dfn[i]){tarjan(i,0);}}write(ans,2);int sum=0;for(int i=1;i<=ans;i++){write(dcl[i],1);for(int j=1;j<=dcl[i];j++)write(dbf[++sum],1);putchar('\n');}}signed main(){solve();return 0;}```