QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#792608 | #999. 边双连通分量 | RDFZchenyy | WA | 12ms | 6484kb | C++14 | 1.2kb | 2024-11-29 11:55:07 | 2024-11-29 11:55:09 |
Judging History
answer
#include<bits/stdc++.h>
#define MAXN 200005
struct Edge{
int v,nxt;
};
int n,m,x,y;
Edge e[MAXN]; int h[MAXN],ec=0;
int dfn[MAXN],low[MAXN],idx;
int st[MAXN],tp;
std::vector<std::vector<int>> ans;
void tarjan(int u,int x){
// std::cout<<"TARJAN"<<' '<<u<<' '<<x<<'\n';
dfn[u]=low[u]=++idx;
st[++tp]=u;
for(int i=h[u];i+1;i=e[i].nxt){
// std::cout<<"EDGE"<<' '<<u<<' '<<i<<' '<<e[i].v<<'\n';
if((x^i)==0||(x^i)==1) continue;
int v=e[i].v;
if(!dfn[v]){
tarjan(v,i),low[u]=std::min(low[u],low[v]);
}else low[u]=std::min(low[u],dfn[v]);
}
if(low[u]==dfn[u]){
std::vector<int> now;
while(st[tp]!=u){
now.push_back(st[tp--]);
}
now.push_back(st[tp--]);
ans.push_back(now);
}
return;
}
void adde(int u,int v){
e[ec].v=v,e[ec].nxt=h[u];
h[u]=ec; ++ec;
return;
}
int main(){
std::ios::sync_with_stdio(false);
memset(h,-1,sizeof(h));
std::cin>>n>>m;
for(int i=1;i<=m;i++){
std::cin>>x>>y;
adde(x,y),adde(y,x);
}
for(int i=0;i<=n-1;i++){
if(!dfn[i]) tarjan(i,-1);
}
std::cout<<ans.size()<<'\n';
for(std::vector<int> nvec:ans){
std::cout<<nvec.size()<<' ';
for(int j:nvec) std::cout<<j<<' ';
std::cout<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5608kb
input:
4 5 0 2 0 1 3 0 2 1 2 3
output:
1 4 1 2 3 0
result:
ok OK
Test #2:
score: 0
Accepted
time: 1ms
memory: 5704kb
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 1 9 5 4 11 0 3 7 6 8 4 12 10 3 2
result:
ok OK
Test #3:
score: 0
Accepted
time: 0ms
memory: 5680kb
input:
2 2 0 1 1 0
output:
1 2 1 0
result:
ok OK
Test #4:
score: -100
Wrong Answer
time: 12ms
memory: 6484kb
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...
output:
0
result:
wrong answer Integer 0 violates the range [1, 200000]