Submission #983709

# Submission time Handle Problem Language Result Execution time Memory
983709 2024-05-16T01:10:25 Z Sandarach151 Naboj (COCI22_naboj) C++17
110 / 110
181 ms 20204 KB
#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    vector<int> down[n];
    vector<int> topsort;
    int edge[n] = { 0 };
    for(int i=0; i<m; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        down[a].push_back(b);
        edge[b]++;
    }
    queue<int> noedge;
    for(int i=0; i<n; i++){
        if(edge[i]==0){
            noedge.push(i);
        }
    }
    while(!noedge.empty()){
        int cur = noedge.front();
        noedge.pop();
        topsort.push_back(cur);
        for(auto u : down[cur]){
            edge[u]--;
            if(edge[u]==0){
                noedge.push(u);
           }
        }
    }
    // for(auto u : topsort){
    //     cout << u << ' ';
    // }
    if(topsort.size()!=n){
        cout << -1 << '\n';
    }
    else{
        cout << n-1 << '\n';
        for(int i=n-2; i>=0; i--){
            cout << topsort[i]+1 << ' ' << 1 << '\n';
        }
    }
    return 0;
}

Compilation message

naboj.cpp: In function 'int main()':
naboj.cpp:40:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   40 |     if(topsort.size()!=n){
      |        ~~~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 15300 KB Output is correct
2 Correct 79 ms 15448 KB Output is correct
3 Correct 37 ms 8148 KB Output is correct
4 Correct 79 ms 15304 KB Output is correct
5 Correct 71 ms 15308 KB Output is correct
6 Correct 69 ms 15300 KB Output is correct
7 Correct 102 ms 15376 KB Output is correct
8 Correct 52 ms 12140 KB Output is correct
9 Correct 73 ms 15308 KB Output is correct
10 Correct 97 ms 15308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 452 KB Output is correct
15 Correct 75 ms 15300 KB Output is correct
16 Correct 79 ms 15448 KB Output is correct
17 Correct 37 ms 8148 KB Output is correct
18 Correct 79 ms 15304 KB Output is correct
19 Correct 71 ms 15308 KB Output is correct
20 Correct 69 ms 15300 KB Output is correct
21 Correct 102 ms 15376 KB Output is correct
22 Correct 52 ms 12140 KB Output is correct
23 Correct 73 ms 15308 KB Output is correct
24 Correct 97 ms 15308 KB Output is correct
25 Correct 104 ms 13476 KB Output is correct
26 Correct 73 ms 15368 KB Output is correct
27 Correct 79 ms 16468 KB Output is correct
28 Correct 101 ms 17972 KB Output is correct
29 Correct 58 ms 15068 KB Output is correct
30 Correct 101 ms 17956 KB Output is correct
31 Correct 14 ms 2652 KB Output is correct
32 Correct 74 ms 14796 KB Output is correct
33 Correct 132 ms 19444 KB Output is correct
34 Correct 86 ms 15156 KB Output is correct
35 Correct 128 ms 19600 KB Output is correct
36 Correct 90 ms 14940 KB Output is correct
37 Correct 119 ms 18372 KB Output is correct
38 Correct 98 ms 17304 KB Output is correct
39 Correct 125 ms 19192 KB Output is correct
40 Correct 117 ms 17912 KB Output is correct
41 Correct 111 ms 18116 KB Output is correct
42 Correct 140 ms 19908 KB Output is correct
43 Correct 83 ms 15744 KB Output is correct
44 Correct 181 ms 20204 KB Output is correct
45 Correct 81 ms 15364 KB Output is correct
46 Correct 139 ms 18112 KB Output is correct