WhileTrueRP @ 2023-12-23 14:58:03
#include<bits/stdc++.h>
using namespace std;
const int N = 5e5+5;
const int M = 2e6+5;
int head[N],nxt[M<<1],to[M<<1];
int dfn[N],low[N];
bool vis[N],vvis[N];
vector<int> ans[N];
int cnt_ans = 0;
int tot = 0,cnt = 0,root;
void add(int x,int y){
nxt[++tot] = head[x];
to[tot] = y;
head[x] = tot;
nxt[++tot] = head[y];
to[tot] = x;
head[y] = tot;
}
void tarjon(int x,int last_edge){
dfn[x] = low[x] = ++cnt;
for(int i=head[x];i;i=nxt[i]){
int y = to[i];
if(!dfn[y]){
tarjon(y,i);
low[x] = min(low[x],low[y]);
if(low[y] > dfn[x]){
printf("%d %d\n",x,y);
vis[i] = true;
vis[i^1] = true;
}
}else if(i != (last_edge^1)){
low[x] = min(low[x],dfn[y]);
}
}
}
void dfs(int x){
ans[cnt_ans].push_back(x);
for(int i=head[x];i;i=nxt[i]){
int y = to[i];
if(vis[i] || vvis[y]){
continue;
}
vvis[y] = true;
dfs(y);
}
}
int main(){
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
int x,y;
scanf("%d%d",&x,&y);
add(x,y);
}
for(int i=1;i<=n;i++){
if(!dfn[i]){
root = i;
tarjon(i,-1);
}
}
for(int i=1;i<=n;i++){
if(!vvis[i]){
cnt_ans ++;
vvis[i] = true;
dfs(i);
}
}
printf("%d\n",cnt_ans);
for(int i=1;i<=cnt_ans;i++){
printf("%d ",ans[i].size());
for(int j=0;j<ans[i].size();j++){
printf("%d ",ans[i][j]);
}
puts("");
}
}
by WhileTrueRP @ 2023-12-23 14:58:31
样例 4,5 错误
by qczrz6v4nhp6u @ 2023-12-23 15:09:33
@WhileTrueRP
int tot = 0;
bool vis[N];
by WhileTrueRP @ 2023-12-23 15:11:07
@ScatteredHope 所以这里有什么错误吗?
by qczrz6v4nhp6u @ 2023-12-23 15:14:11
@WhileTrueRP
int tot = 1;
bool vis[M<<1];
by WhileTrueRP @ 2023-12-23 15:20:43
@ScatteredHope 求割桥的部分好像是对了的,但是样例 4 还是不对,我再自己调一调吧!
感谢!
by qczrz6v4nhp6u @ 2023-12-23 15:22:29
@WhileTrueRP 你说得对,但我改了这两个就过了
by qczrz6v4nhp6u @ 2023-12-23 15:23:54
噢,你是不是调试没删
by WhileTrueRP @ 2023-12-23 15:24:51
@ScatteredHope 哦,好像是我交错题了