QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#646540 | #999. 边双连通分量 | Zhou_JK | RE | 0ms | 9564kb | C++23 | 2.1kb | 2024-10-17 00:35:23 | 2024-10-17 00:35:24 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int N=100005;
struct Trajan_EBC
{
int n,m;
Trajan_EBC(int _n=0):n(_n),m(0){}
void init(int _n)
{
n=_n,m=0;
return;
}
vector<pair<int,int>>G[N];
void add_edge(int u,int v)
{
m++;
G[u].emplace_back(v,m);
G[v].emplace_back(u,m);
return;
}
int dfn[N],low[N],Index;
bool ins[N];
stack<int>s;
int bel[N],tot;
vector<int>block[N];
void dfs(int u,int prev)
{
dfn[u]=low[u]=++Index;
ins[u]=true;
s.push(u);
for(auto [v,id]:G[u])
{
if(id==prev) continue;
if(!dfn[v])
{
dfs(v,id);
low[u]=min(low[u],low[v]);
}
else if(ins[v]) low[u]=min(low[u],dfn[v]);
}
if(dfn[u]==low[u])
{
tot++;
block[tot].clear();
while(!s.empty()&&s.top()!=u)
{
int v=s.top();
s.pop();
ins[v]=false;
bel[v]=tot;
block[tot].push_back(v);
}
s.pop();
ins[u]=false;
bel[u]=tot;
block[tot].push_back(u);
}
return;
}
void tarjan()
{
fill(dfn+1,dfn+n+1,0);
fill(low+1,low+n+1,0);
Index=0;
fill(bel+1,bel+n+1,0);
tot=0;
fill(ins+1,ins+n+1,false);
for(int i=1;i<=n;i++)
if(!dfn[i]) dfs(i,0);
return;
}
};
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int n,m;
cin>>n>>m;
Trajan_EBC tebc(n);
for(int i=1;i<=m;i++)
{
int u,v;
cin>>u>>v;
u++,v++;
tebc.add_edge(u,v);
}
tebc.tarjan();
int tot=tebc.tot;
cout<<tot<<"\n";
for(int i=1;i<=tot;i++)
{
int l=tebc.block[i].size();
cout<<l<<" ";
for(int u:tebc.block[i])
cout<<u-1<<" ";
cout<<"\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 9564kb
input:
4 5 0 2 0 1 3 0 2 1 2 3
output:
1 4 3 1 2 0
result:
ok OK
Test #2:
score: 0
Accepted
time: 0ms
memory: 9560kb
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 11 4 5 1 9 0 3 6 7 8 4 12 3 10 2
result:
ok OK
Test #3:
score: 0
Accepted
time: 0ms
memory: 9496kb
input:
2 2 0 1 1 0
output:
1 2 1 0
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...