QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#482136#906. 强连通分量5k_sync_closerRE 1ms5856kbC++201.5kb2024-07-17 17:32:122024-07-17 17:32:12

Judging History

你现在查看的是最新测评结果

  • [2024-07-17 17:32:12]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5856kb
  • [2024-07-17 17:32:12]
  • 提交

answer

#include <cstdio>
#include <queue>
#include <vector>
using namespace std;
struct E
{
    int v, t;
} e[100050];
queue<int> q;
vector<int> v[100050], g[100050];
bool b[100050];
int n, m, c, _, C, L, d[100050], l[100050], h[100050], P[100050], S[100050], I[100050];
void A(int u, int v) { e[++c] = {v, h[u]}, h[u] = c; }
void T(int u)
{
    d[u] = l[u] = ++_, b[S[++L] = u] = 1;
    for (int i = h[u], v; i; i = e[i].t)
        if (!d[v = e[i].v])
            T(v), l[u] = min(l[u], l[v]);
        else if (b[v])
            l[u] = min(l[u], d[v]);
    if (d[u] == l[u])
    {
        ++C;
        int z = -1;
        while (z != u)
            b[z = S[L--]] = 0, v[P[z] = C].push_back(z);
    }
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0, u, v; i < m; ++i)
        scanf("%d%d", &u, &v), A(u, v);
    for (int i = 0; i < n; ++i)
        if (!d[i])
            T(i);
    printf("%d\n", C);
    for (int u = 0; u < n; ++u)
        for (int i = h[u], v; i; i = e[i].t)
            if (P[u] != P[v = e[i].v])
                g[P[u]].push_back(P[v]), ++I[P[v]];
    for (int i = 1; i <= C; ++i)
        if (!I[i])
            q.push(i);
    while (!q.empty())
    {
        int u = q.front();
        q.pop();
        printf("%d ", v[u].size());
        for (auto i : v[u])
            printf("%d ", i);
        puts("");
        for (auto v : g[u])
            if (!--I[v])
                q.push(v);
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5856kb

input:

6 7
1 4
5 2
3 0
5 5
4 1
0 3
4 2

output:

4
2 3 0 
2 4 1 
1 5 
1 2 

result:

ok OK

Test #2:

score: -100
Runtime Error

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:


result: