QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#44768 | #906. 强连通分量 | zmwang# | WA | 12ms | 50640kb | C++14 | 1.2kb | 2022-08-21 15:48:13 | 2022-08-21 15:48:13 |
Judging History
answer
#include<bits/stdc++.h>
#define int ll
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define qr read()
#define in(x) x=read()
#define nc getchar
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
char ch=' ';
ll f=1,x=0;
for(;!isdigit(ch);ch=nc())if(ch=='-')f*=-1;
for(;isdigit(ch);ch=nc())x=x*10+ch-'0';
return f*x;
}
int top=0,s[1000010],dfn[1000010],low[1000010],tim=0,ins[1000010],tot=0;
vector<int>ans[1000010],e[1000010];
void tarjan(int x)
{
dfn[x]=low[x]=++tim;
ins[x]=1;
s[++top]=x;
for(auto i:e[x])
{
if(!dfn[i])
{
tarjan(i);
low[x]=min(low[x],low[i]);
}
else if(ins[i])low[x]=min(low[x],dfn[i]);
}
if(low[x]==dfn[x])
{
int now=0;
tot++;
do
{
now=s[top--];
ins[now]=0;
ans[tot].push_back(now);
}while(now!=x);
}
}
signed main()
{
// freopen("a.in","r",stdin);
// freopen(".out","w",stdout);
int n=qr,m=qr;
for(int i=1;i<=m;i++)
{
int x=qr,y=qr;
e[x].push_back(y);
}
for(int i=0;i<n;i++)if(!dfn[i])tarjan(i);
cout<<tot<<'\n';
for(int i=1;i<=tot;i++)
{
cout<<ans[i].size()<<' ';
for(auto j:ans[i])cout<<j<<' ';cout<<'\n';
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 12ms
memory: 50640kb
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)