Submission #572585

# Submission time Handle Problem Language Result Execution time Memory
572585 2022-06-04T17:55:23 Z model_code Naboj (COCI22_naboj) C++17
110 / 110
328 ms 14692 KB
#include <bits/stdc++.h>

using namespace std;

const int N=2e5+5;

int n, m;
vector <int> ls[N], topo;
int in[N], bio[N];
queue <int> Q;

void dfs(int node) {
    if (bio[node] == 1) {
        printf("-1\n");
        exit(0);
    }
    if (bio[node] == 2) return;
    bio[node] = 1;
    for (int x:ls[node]) dfs(x);
    bio[node] = 2;
}

void solve() {
    for (int i=1; i<=n; ++i) {
        if (!bio[i]) dfs(i);
        if (in[i] == 0) {
            Q.push(i);
        }
    }
    while (!Q.empty()) {
        int node = Q.front();
        Q.pop();
        topo.push_back(node);
        for (int sus:ls[node]) {
            in[sus]--;
            if (in[sus] == 0) Q.push(sus);
        }
    }
    printf("%d\n", (int)topo.size());
    for (int x:topo) printf("%d 0\n", x);
}

void load() {
    scanf("%d %d", &n, &m);
    for (int i=0; i<m; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        ls[a].push_back(b);
        in[b]++;
    }
}

int main() {
    load();
    solve();
    return 0;
}

Compilation message

naboj.cpp: In function 'void load()':
naboj.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
naboj.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 4 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 4 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 195 ms 13528 KB Output is correct
2 Correct 159 ms 13600 KB Output is correct
3 Correct 67 ms 9460 KB Output is correct
4 Correct 180 ms 13600 KB Output is correct
5 Correct 187 ms 13648 KB Output is correct
6 Correct 182 ms 13572 KB Output is correct
7 Correct 155 ms 13564 KB Output is correct
8 Correct 110 ms 11652 KB Output is correct
9 Correct 158 ms 13556 KB Output is correct
10 Correct 174 ms 13632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 4 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 4 ms 4948 KB Output is correct
15 Correct 195 ms 13528 KB Output is correct
16 Correct 159 ms 13600 KB Output is correct
17 Correct 67 ms 9460 KB Output is correct
18 Correct 180 ms 13600 KB Output is correct
19 Correct 187 ms 13648 KB Output is correct
20 Correct 182 ms 13572 KB Output is correct
21 Correct 155 ms 13564 KB Output is correct
22 Correct 110 ms 11652 KB Output is correct
23 Correct 158 ms 13556 KB Output is correct
24 Correct 174 ms 13632 KB Output is correct
25 Correct 240 ms 10604 KB Output is correct
26 Correct 163 ms 11608 KB Output is correct
27 Correct 212 ms 11936 KB Output is correct
28 Correct 238 ms 12420 KB Output is correct
29 Correct 147 ms 11176 KB Output is correct
30 Correct 259 ms 12436 KB Output is correct
31 Correct 33 ms 5964 KB Output is correct
32 Correct 179 ms 12708 KB Output is correct
33 Correct 302 ms 14420 KB Output is correct
34 Correct 159 ms 12824 KB Output is correct
35 Correct 328 ms 14376 KB Output is correct
36 Correct 173 ms 12532 KB Output is correct
37 Correct 311 ms 14084 KB Output is correct
38 Correct 261 ms 13568 KB Output is correct
39 Correct 294 ms 14424 KB Output is correct
40 Correct 217 ms 13888 KB Output is correct
41 Correct 287 ms 13936 KB Output is correct
42 Correct 311 ms 14592 KB Output is correct
43 Correct 216 ms 13124 KB Output is correct
44 Correct 289 ms 14692 KB Output is correct
45 Correct 159 ms 12836 KB Output is correct
46 Correct 277 ms 13832 KB Output is correct