QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#342449 | #999. 边双连通分量 | shuopihua# | RE | 3ms | 8524kb | C++14 | 1.4kb | 2024-03-01 11:25:58 | 2024-03-01 11:25:58 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
int n,m,cnt=1,tm,tot;
int h[200005];
bool ok[200005];
int uu[200005];
int vv[200005];
int dfn[200005];
int low[200005];
bool vis[200005];
struct node{int v,nxt;}edge[400005];
vector <int> g[200005];
inline void addedge(int u,int v){
edge[++cnt]={v,h[u]};
h[u]=cnt;return ;
}
inline void in(int &n){
n=0;
char c=getchar();
while(c<'0' || c>'9') c=getchar();
while(c>='0'&&c<='9') n=n*10+c-'0',c=getchar();
return ;
}
inline void tarjan(int u,int in){
dfn[u]=low[u]=++tm;
for(int i=h[u];i;i=edge[i].nxt){
int v=edge[i].v;
if(!dfn[v]){
tarjan(v,i);
if(dfn[u]<low[v])
ok[i]=ok[i^1]=1;
low[u]=min(low[u],low[v]);
}
else if(i!=(in^1)) low[u]=min(low[u],dfn[v]);
}
return ;
}
inline void dfs(int u){
vis[u]=1;
g[tot].emplace_back(u);
for(int i=h[u];i;i=edge[i].nxt){
if(ok[i]||vis[edge[i].v]) continue;
dfs(edge[i].v);
}
return ;
}
int main(){
in(n),in(m);
for(int i=1;i<=m;i++){
int u,v;
in(u),in(v);
u++,v++;
uu[i]=u,vv[i]=v;
addedge(u,v);
addedge(v,u);
}
for(int i=1;i<=n;i++)
if(!dfn[i]) tarjan(i,0);
for(int i=1;i<=n;i++)
if(!vis[i]) tot++,dfs(i);
printf("%d\n",tot);
for(int i=1;i<=tot;i++){
printf("%d ",(int) g[i].size());
for(int v:g[i]) printf("%d ",v-1);
puts("");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 8476kb
input:
4 5 0 2 0 1 3 0 2 1 2 3
output:
1 4 0 3 2 1
result:
ok OK
Test #2:
score: 0
Accepted
time: 0ms
memory: 8524kb
input:
13 21 4 5 8 7 12 3 3 10 1 5 10 2 0 0 11 4 2 12 9 1 9 0 7 8 7 6 9 1 8 2 12 10 11 0 8 6 3 2 5 9 4 11
output:
3 6 0 11 4 5 9 1 4 2 3 10 12 3 6 8 7
result:
ok OK
Test #3:
score: 0
Accepted
time: 0ms
memory: 8472kb
input:
2 2 0 1 1 0
output:
1 2 0 1
result:
ok OK
Test #4:
score: -100
Runtime Error
input:
200000 200000 127668 148778 77100 11865 85144 199231 39485 84917 102044 187263 130204 174776 26220 198288 162188 12078 92196 146334 120537 38083 150353 160479 18707 6545 101149 25450 62271 9177 38892 6454 11709 191939 89247 145109 140599 121858 197410 148980 55975 169098 128576 59852 68224 182347 89...