QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#480856 | #906. 强连通分量 | wanglianda# | WA | 0ms | 32492kb | C++14 | 1.0kb | 2024-07-16 19:14:10 | 2024-07-16 19:14:10 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=5e5;
ll read(){
ll S=0,F=1;char ch=getchar();
while(!isdigit(ch)){
if(ch=='-')F*=-1;
ch=getchar();
}while(isdigit(ch)){
S=(S<<3)+(S<<1)+(ch^48);
ch=getchar();
}return S*F;
}ll n,m,u,v,lts,tp,sta[N+10],vis[N+10],dfn[N+10],low[N+10],cnt;
vector<ll >vs[N+10],to[N+10];
void dfs(ll id){
low[id]=dfn[id]=++cnt;
sta[++tp]=id;vis[id]=1;
for(ll i=0;i<to[id].size();i++){
if(!dfn[to[id][i]]){
dfs(to[id][i]);
low[id]=min(low[id],low[to[id][i]]);
}else if(vis[to[id][i]])low[id]=min(low[id],dfn[to[id][i]]);
}if(low[id]==dfn[id]){
lts++;do{
vs[lts].push_back(sta[tp--]);
vis[sta[tp+1]]=0;
}while(sta[tp+1]!=id);
}return;
}int main(){
n=read();m=read();
while(m--){
u=read()+1;v=read()+1;
to[u].push_back(v);
}for(ll i=1;i<=n;i++)if(!dfn[i])dfs(i);
printf("%lld\n",lts);
for(ll i=1;i<=lts;i++){
printf("%lld ",vs[i].size());
for(ll j=0;j<vs[i].size();j++)printf("%lld ",vs[i][j]-1);
putchar('\n');
}return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 32492kb
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)