Submission #781421

# Submission time Handle Problem Language Result Execution time Memory
781421 2023-07-13T05:55:34 Z makanhulia Naboj (COCI22_naboj) C++17
110 / 110
151 ms 20828 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 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 16036 KB Output is correct
2 Correct 80 ms 16152 KB Output is correct
3 Correct 37 ms 10700 KB Output is correct
4 Correct 77 ms 16096 KB Output is correct
5 Correct 100 ms 16112 KB Output is correct
6 Correct 91 ms 16148 KB Output is correct
7 Correct 86 ms 16124 KB Output is correct
8 Correct 74 ms 13608 KB Output is correct
9 Correct 76 ms 16052 KB Output is correct
10 Correct 77 ms 16072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 77 ms 16036 KB Output is correct
16 Correct 80 ms 16152 KB Output is correct
17 Correct 37 ms 10700 KB Output is correct
18 Correct 77 ms 16096 KB Output is correct
19 Correct 100 ms 16112 KB Output is correct
20 Correct 91 ms 16148 KB Output is correct
21 Correct 86 ms 16124 KB Output is correct
22 Correct 74 ms 13608 KB Output is correct
23 Correct 76 ms 16052 KB Output is correct
24 Correct 77 ms 16072 KB Output is correct
25 Correct 86 ms 15432 KB Output is correct
26 Correct 82 ms 15308 KB Output is correct
27 Correct 114 ms 16560 KB Output is correct
28 Correct 111 ms 18372 KB Output is correct
29 Correct 80 ms 14208 KB Output is correct
30 Correct 120 ms 18276 KB Output is correct
31 Correct 19 ms 6916 KB Output is correct
32 Correct 91 ms 15492 KB Output is correct
33 Correct 138 ms 20044 KB Output is correct
34 Correct 89 ms 15928 KB Output is correct
35 Correct 141 ms 20192 KB Output is correct
36 Correct 89 ms 15312 KB Output is correct
37 Correct 131 ms 19180 KB Output is correct
38 Correct 131 ms 17844 KB Output is correct
39 Correct 137 ms 20008 KB Output is correct
40 Correct 120 ms 18576 KB Output is correct
41 Correct 145 ms 18612 KB Output is correct
42 Correct 147 ms 20628 KB Output is correct
43 Correct 122 ms 16556 KB Output is correct
44 Correct 151 ms 20828 KB Output is correct
45 Correct 85 ms 15940 KB Output is correct
46 Correct 121 ms 18648 KB Output is correct