QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#473888 | #906. 强连通分量 | windviolet# | WA | 0ms | 6588kb | C++14 | 1.2kb | 2024-07-12 14:49:59 | 2024-07-12 14:49:59 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF=1e18+9;
const int N=1e5+5;
struct Edge{
int v,c,nxt;
}e[N<<1];
int h[N],tot;
void add(int u,int v){
tot++;
e[tot].v=v;
e[tot].nxt=h[u];
h[u]=tot;
}
struct Vertex{
int dfn,low,vis;
}ver[N];
int q[N],l=1,r=0;
int dfncnt=0;
vector<int>sta[N];
int stacnt=0;
int n,m;
void tarjan(int start){
ver[start].dfn=++dfncnt;
ver[start].low=dfncnt;
q[++r]=start;
ver[start].vis=1;
for(int i=h[start];i;i=e[i].nxt){
int v=e[i].v;
if(!ver[v].dfn){
tarjan(v);
ver[start].low=min(ver[start].low,ver[v].low);
}
else if(ver[v].vis){
ver[start].low=min(ver[start].low,ver[v].dfn);
}
}
if(ver[start].dfn==ver[start].low){
stacnt++;
while(l<=r){
int u=q[r--];
sta[stacnt].push_back(u);
ver[u].vis=0;
if(u==start)break;
}
}
}
signed main(){
scanf("%lld%lld",&n,&m);
for(int i=1;i<=m;i++){
int u,v;
scanf("%lld%lld",&u,&v);
add(u,v);
}
for(int i=0;i<n;i++){
if(!ver[i].dfn)tarjan(i);
}
cout<<stacnt<<"\n";
for(int i=1;i<=stacnt;i++){
int lenn=sta[i].size();
cout<<lenn<<" ";
for(int j=1;j<=lenn;j++)cout<<sta[i][j-1]<<" ";
cout<<"\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 6588kb
input:
6 7 1 4 5 2 3 0 5 5 4 1 0 3 4 2
output:
4 2 3 0 1 2 2 4 1 1 5
result:
wrong answer 5 is later than 2, but there is an edge (5, 2)