QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#479639 | #906. 强连通分量 | Gold_Dino# | WA | 4ms | 18224kb | C++14 | 1.2kb | 2024-07-15 19:45:32 | 2024-07-15 19:45:34 |
Judging History
answer
#include <bits/stdc++.h>
const int N = 500007;
int n, m;
struct
{
int v, nxt;
} e[N];
std::vector<int> st[N];
int dfn[N], low[N], pdfn, stk[N], top, head[N], vis[N], pscc, scc[N], tot;
void Add(int u, int v) { e[++tot] = {v, head[u]}, head[u] = tot; }
void DFS(int u)
{
// fprintf(stderr, "%d\n", u);
low[u] = dfn[u] = ++pdfn;
stk[++top] = u, vis[u] = 1;
for (int i = head[u]; i; i = e[i].nxt)
{
auto &x = e[i];
if (!dfn[x.v])
DFS(x.v), low[u] = std::min(low[u], low[x.v]);
else if (vis[x.v])
low[u] = std::min(low[u], dfn[x.v]);
}
if (low[u] == dfn[u])
{
++pscc;
while (vis[u])
{
int x = stk[top--];
vis[x] = 0, scc[x] = pscc, st[pscc].push_back(x);
}
}
}
int main()
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; ++i)
{
int u, v;
scanf("%d%d", &u, &v);
Add(u, v);
}
for (int i = 0; i < n; ++i)
if (!dfn[i])
DFS(i);
printf("%d\n", pscc);
// fprintf(stderr, "%d\n", dfn[2]);
for (int i = 1; i <= pscc; ++i)
{
printf("%d", (int)st[i].size());
for (int x : st[i])
printf(" %d", x);
printf("\n");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 18224kb
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)