QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#93095 | #906. 强连通分量 | Thunder_S# | WA | 547ms | 48584kb | C++14 | 1.7kb | 2023-03-31 10:50:49 | 2023-03-31 10:50:50 |
Judging History
answer
#include<cstdio>
#include<vector>
#define N 500005
using namespace std;
int n,m,tot,cnt,top,num,dfn[N],low[N],sta[N],col[N];
bool bj[N];
struct node {int to,next,head;}a[N];
struct Edge {int x,y;}edg[N];
vector<int> f[N];
int min(int x,int y) {return x<y?x:y;}
void add(int x,int y) {a[++tot].to=y;a[tot].next=a[x].head;a[x].head=tot;}
void dfs(int x)
{
dfn[x]=low[x]=++cnt;
sta[++top]=x;
for (int i=a[x].head;i;i=a[i].next)
{
int y=a[i].to;
if (!dfn[y])
{
dfs(y);
low[x]=min(low[x],low[y]);
}
else if (!col[y]) low[x]=min(low[x],dfn[y]);
}
if (low[x]==dfn[x])
{
col[x]=++num;f[num].push_back(x);
while (sta[top]!=x)
{
f[num].push_back(sta[top]);
col[sta[top--]]=num;
}
top--;
}
}
int main()
{
scanf("%d%d",&n,&m);
for (int i=1;i<=m;++i)
{
int x,y;
scanf("%d%d",&x,&y);++x;++y;
add(x,y);
edg[i].x=x;edg[i].y=y;
}
for (int i=1;i<=n;++i)
if (!dfn[i])
dfs(i);
printf("%d\n",num);
for (int i=1;i<=m;++i)
{
int x=edg[i].x,y=edg[i].y;
if (!bj[col[x]])
{
int now=col[x];
printf("%d ",f[now].size());
for (int j=0;j<f[now].size();++j)
printf("%d ",f[now][j]-1);
printf("\n");
bj[now]=true;
}
if (!bj[col[y]])
{
int now=col[y];
printf("%d ",f[now].size());
for (int j=0;j<f[now].size();++j)
printf("%d ",f[now][j]-1);
printf("\n");
bj[now]=true;
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 4ms
memory: 20904kb
input:
6 7 1 4 5 2 3 0 5 5 4 1 0 3 4 2
output:
4 2 1 4 1 5 1 2 2 0 3
result:
ok OK
Test #2:
score: -100
Wrong Answer
time: 547ms
memory: 48584kb
input:
500000 500000 389812 410922 255712 339244 274009 248522 347288 199231 235313 301629 469588 84917 364188 449407 392348 436920 26220 198288 162188 468965 274222 92196 463222 408478 231663 467768 382681 38083 412497 160479 280851 268689 101149 25450 62271 9177 38892 268598 273853 250782 191939 89247 40...
output:
499590 1 389812 1 410922 1 255712 1 339244 1 274009 1 248522 1 347288 1 199231 1 235313 1 301629 1 469588 1 84917 1 364188 1 449407 1 392348 1 436920 1 26220 1 198288 1 162188 1 468965 1 274222 1 92196 1 463222 1 408478 1 231663 1 467768 1 382681 1 38083 1 412497 1 16047...
result:
wrong output format Unexpected end of file - int32 expected