Submission #633138

# Submission time Handle Problem Language Result Execution time Memory
633138 2022-08-21T16:48:16 Z Hacv16 Naboj (COCI22_naboj) C++17
110 / 110
261 ms 62404 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MAX = 2e6 + 15;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

#define pb push_back
#define sz(x) (int) x.size()
#define fr first
#define sc second
#define mp make_pair
#define all(x) x.begin(), x.end()
#define dbg(x) cerr << #x << ": " << "[ " << x << " ]\n"

int n, m, ingrau[MAX];
vector<int> adj[MAX];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 

    cin >> n >> m;

    while(m--){
        int u, v; cin >> u >> v;
        adj[u].pb(v);

        ingrau[v]++;
    }    

    vector<int> q;

    for(int i = 1; i <= n; i++)
        if(ingrau[i] == 0) q.pb(i);
    
    int cur = 0;

    while(cur < sz(q)){
        int u = q[cur];

        for(auto v : adj[u]){
            ingrau[v]--;
            
            if(!ingrau[v])
                q.pb(v);
        }

        cur++;
    }

    if(sz(q) != n){
        cout << -1 << '\n';
    }else{
        cout << sz(q) << '\n';

        for(auto x : q) 
            cout << x << ' ' << 0 << '\n';
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47252 KB Output is correct
2 Correct 24 ms 47292 KB Output is correct
3 Correct 24 ms 47252 KB Output is correct
4 Correct 24 ms 47296 KB Output is correct
5 Correct 24 ms 47252 KB Output is correct
6 Correct 25 ms 47300 KB Output is correct
7 Correct 24 ms 47188 KB Output is correct
8 Correct 28 ms 47276 KB Output is correct
9 Correct 27 ms 47188 KB Output is correct
10 Correct 23 ms 47236 KB Output is correct
11 Correct 24 ms 47300 KB Output is correct
12 Correct 24 ms 47188 KB Output is correct
13 Correct 28 ms 47188 KB Output is correct
14 Correct 25 ms 47180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 132 ms 57320 KB Output is correct
2 Correct 132 ms 57392 KB Output is correct
3 Correct 82 ms 52452 KB Output is correct
4 Correct 128 ms 57320 KB Output is correct
5 Correct 159 ms 57408 KB Output is correct
6 Correct 152 ms 57296 KB Output is correct
7 Correct 128 ms 57312 KB Output is correct
8 Correct 116 ms 55152 KB Output is correct
9 Correct 138 ms 57308 KB Output is correct
10 Correct 128 ms 57304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47252 KB Output is correct
2 Correct 24 ms 47292 KB Output is correct
3 Correct 24 ms 47252 KB Output is correct
4 Correct 24 ms 47296 KB Output is correct
5 Correct 24 ms 47252 KB Output is correct
6 Correct 25 ms 47300 KB Output is correct
7 Correct 24 ms 47188 KB Output is correct
8 Correct 28 ms 47276 KB Output is correct
9 Correct 27 ms 47188 KB Output is correct
10 Correct 23 ms 47236 KB Output is correct
11 Correct 24 ms 47300 KB Output is correct
12 Correct 24 ms 47188 KB Output is correct
13 Correct 28 ms 47188 KB Output is correct
14 Correct 25 ms 47180 KB Output is correct
15 Correct 132 ms 57320 KB Output is correct
16 Correct 132 ms 57392 KB Output is correct
17 Correct 82 ms 52452 KB Output is correct
18 Correct 128 ms 57320 KB Output is correct
19 Correct 159 ms 57408 KB Output is correct
20 Correct 152 ms 57296 KB Output is correct
21 Correct 128 ms 57312 KB Output is correct
22 Correct 116 ms 55152 KB Output is correct
23 Correct 138 ms 57308 KB Output is correct
24 Correct 128 ms 57304 KB Output is correct
25 Correct 133 ms 57296 KB Output is correct
26 Correct 151 ms 57528 KB Output is correct
27 Correct 156 ms 58616 KB Output is correct
28 Correct 175 ms 60164 KB Output is correct
29 Correct 128 ms 56936 KB Output is correct
30 Correct 170 ms 60016 KB Output is correct
31 Correct 49 ms 49144 KB Output is correct
32 Correct 144 ms 57084 KB Output is correct
33 Correct 230 ms 61612 KB Output is correct
34 Correct 162 ms 57420 KB Output is correct
35 Correct 243 ms 61736 KB Output is correct
36 Correct 184 ms 56888 KB Output is correct
37 Correct 215 ms 60796 KB Output is correct
38 Correct 181 ms 59520 KB Output is correct
39 Correct 245 ms 61520 KB Output is correct
40 Correct 218 ms 60132 KB Output is correct
41 Correct 212 ms 60120 KB Output is correct
42 Correct 261 ms 62216 KB Output is correct
43 Correct 151 ms 57916 KB Output is correct
44 Correct 248 ms 62404 KB Output is correct
45 Correct 141 ms 57376 KB Output is correct
46 Correct 200 ms 60112 KB Output is correct