Submission #704857

# Submission time Handle Problem Language Result Execution time Memory
704857 2023-03-03T05:50:49 Z PixelCat Naboj (COCI22_naboj) C++14
110 / 110
252 ms 23928 KB
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define eb emplace_back
#define int LL
using namespace std;
using LL = long long;
using pii = pair<int, int>;

const int MAXN = 200020;

vector<int> adj[MAXN];
int deg[MAXN];

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // nya ><
    int n, m; cin >> n >> m;
    For(i, 1, m) {
        int a, b; cin >> a >> b;
        adj[a].eb(b);
        deg[b]++;
    }
    queue<int> que;
    vector<int> ans;
    For(i, 1, n) if(deg[i] == 0) {
        que.emplace(i);
    }
    while(!que.empty()) {
        int now = que.front(); que.pop();
        ans.eb(now);
        for(auto &i:adj[now]) {
            deg[i]--;
            if(!deg[i]) que.emplace(i);
        }
    }
    if(sz(ans) != n) {
        cout << "-1\n";
    } else {
        cout << n << "\n";
        reverse(all(ans));
        for(auto &i:ans) cout << i << " 1\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5024 KB Output is correct
3 Correct 3 ms 5024 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 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 5024 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 5020 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 17452 KB Output is correct
2 Correct 104 ms 17420 KB Output is correct
3 Correct 42 ms 11468 KB Output is correct
4 Correct 113 ms 17468 KB Output is correct
5 Correct 111 ms 17472 KB Output is correct
6 Correct 99 ms 17432 KB Output is correct
7 Correct 101 ms 17428 KB Output is correct
8 Correct 102 ms 14704 KB Output is correct
9 Correct 101 ms 17500 KB Output is correct
10 Correct 116 ms 17476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5024 KB Output is correct
3 Correct 3 ms 5024 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 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 5024 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 5020 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5020 KB Output is correct
15 Correct 124 ms 17452 KB Output is correct
16 Correct 104 ms 17420 KB Output is correct
17 Correct 42 ms 11468 KB Output is correct
18 Correct 113 ms 17468 KB Output is correct
19 Correct 111 ms 17472 KB Output is correct
20 Correct 99 ms 17432 KB Output is correct
21 Correct 101 ms 17428 KB Output is correct
22 Correct 102 ms 14704 KB Output is correct
23 Correct 101 ms 17500 KB Output is correct
24 Correct 116 ms 17476 KB Output is correct
25 Correct 126 ms 17756 KB Output is correct
26 Correct 115 ms 17404 KB Output is correct
27 Correct 138 ms 18620 KB Output is correct
28 Correct 171 ms 21068 KB Output is correct
29 Correct 109 ms 17304 KB Output is correct
30 Correct 170 ms 20836 KB Output is correct
31 Correct 21 ms 7264 KB Output is correct
32 Correct 114 ms 16920 KB Output is correct
33 Correct 220 ms 22976 KB Output is correct
34 Correct 115 ms 17440 KB Output is correct
35 Correct 218 ms 23016 KB Output is correct
36 Correct 136 ms 16780 KB Output is correct
37 Correct 206 ms 21672 KB Output is correct
38 Correct 188 ms 19976 KB Output is correct
39 Correct 252 ms 22700 KB Output is correct
40 Correct 184 ms 21012 KB Output is correct
41 Correct 203 ms 20764 KB Output is correct
42 Correct 223 ms 23612 KB Output is correct
43 Correct 154 ms 18104 KB Output is correct
44 Correct 235 ms 23928 KB Output is correct
45 Correct 143 ms 17404 KB Output is correct
46 Correct 178 ms 20900 KB Output is correct