QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#129376 | #906. 强连通分量 | yixiuge777# | WA | 8ms | 30624kb | C++14 | 1.3kb | 2023-07-22 17:34:41 | 2023-07-22 17:34:44 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#define ll long long
#define N 500010
using namespace std;
ll read(){
char cc;
while(1){cc=getchar();if((cc>='0'&&cc<='9')||cc=='-')break;}
ll sum=0,flag=1;
cc=='-'?flag=-1:sum=(cc^48);
while(1){cc=getchar();if(!(cc>='0'&&cc<='9'))break;sum=(sum<<1)+(sum<<3)+(cc^48);}
return sum*flag;
}
void write(ll x){
if(!x)putchar('0');
if(x<0){x=-x;putchar('-');}
ll cc[25],cntt=0;
while(x){cc[++cntt]=x%10;x/=10;}
for(ll i=cntt;i>=1;i--)putchar(cc[i]+'0');
putchar(' ');
}
vector<ll>b[N],c[N];
ll n,m,vis[N],q[N],hh=0,shu[N],dfn[N],low[N],tot=0,cnt=0;
void dfs(ll x){
dfn[x]=low[x]=++tot;
q[++hh]=x;vis[x]=1;
for(ll v:b[x]){
if(!dfn[v]){dfs(v);low[x]=min(low[x],low[v]);}
else if(vis[v])low[x]=min(low[x],dfn[v]);
}
if(dfn[x]==low[x]){
cnt++;
while(q[hh]!=x){c[cnt].push_back(q[hh]);vis[q[hh]]=0;hh--;}
c[cnt].push_back(q[hh]);vis[q[hh]]=0;hh--;
}
}
int main(){
// freopen("data.in","r",stdin);
n=read();m=read();
for(ll i=1;i<=m;i++){
ll u=read(),v=read();
b[u].push_back(v);
}
for(ll i=0;i<n;i++)if(!dfn[i])dfs(i);
write(cnt);putchar('\n');
for(ll i=1;i<=cnt;i++){
write(c[i].size());for(ll v:c[i])write(v);putchar('\n');
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 8ms
memory: 30624kb
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)