# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
782203 | 2023-07-13T16:18:10 Z | andecaandeci | Naboj (COCI22_naboj) | C++17 | 175 ms | 17768 KB |
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pii pair<int,int> #define pll pair<long long, long long> long long n,m,deg[200005]; vector<long long> vec[200005]; queue<long long> q; int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); long long tc,i,j; cin>>n>>m; for(i=1;i<=m;i++) { long long u,v; cin>>u>>v; deg[v]++; vec[u].push_back(v); } vector<long long> ans; for(i=1;i<=n;i++) { if(deg[i] == 0) { q.push(i); ans.push_back(i); } } while(!q.empty()) { long long node = q.front(); q.pop(); for(auto it : vec[node]) { deg[it]--; if(deg[it] == 0) { q.push(it); ans.push_back(it); } } } for(i=1;i<=n;i++) { if(deg[i] > 0) { break; } } if(i <= n) { cout<<-1<<'\n'; } else { cout<<ans.size()<<'\n'; for(auto it : ans) { cout<<it<<" 0\n"; } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4948 KB | Output is correct |
2 | Correct | 3 ms | 4960 KB | Output is correct |
3 | Correct | 2 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 | 3 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 | 3 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 | 3 ms | 4948 KB | Output is correct |
14 | Correct | 2 ms | 4948 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 78 ms | 14848 KB | Output is correct |
2 | Correct | 70 ms | 14756 KB | Output is correct |
3 | Correct | 35 ms | 10104 KB | Output is correct |
4 | Correct | 66 ms | 14800 KB | Output is correct |
5 | Correct | 79 ms | 14852 KB | Output is correct |
6 | Correct | 74 ms | 14760 KB | Output is correct |
7 | Correct | 67 ms | 14812 KB | Output is correct |
8 | Correct | 53 ms | 12600 KB | Output is correct |
9 | Correct | 76 ms | 14752 KB | Output is correct |
10 | Correct | 94 ms | 14904 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4948 KB | Output is correct |
2 | Correct | 3 ms | 4960 KB | Output is correct |
3 | Correct | 2 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 | 3 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 | 3 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 | 3 ms | 4948 KB | Output is correct |
14 | Correct | 2 ms | 4948 KB | Output is correct |
15 | Correct | 78 ms | 14848 KB | Output is correct |
16 | Correct | 70 ms | 14756 KB | Output is correct |
17 | Correct | 35 ms | 10104 KB | Output is correct |
18 | Correct | 66 ms | 14800 KB | Output is correct |
19 | Correct | 79 ms | 14852 KB | Output is correct |
20 | Correct | 74 ms | 14760 KB | Output is correct |
21 | Correct | 67 ms | 14812 KB | Output is correct |
22 | Correct | 53 ms | 12600 KB | Output is correct |
23 | Correct | 76 ms | 14752 KB | Output is correct |
24 | Correct | 94 ms | 14904 KB | Output is correct |
25 | Correct | 86 ms | 12712 KB | Output is correct |
26 | Correct | 72 ms | 13512 KB | Output is correct |
27 | Correct | 86 ms | 13900 KB | Output is correct |
28 | Correct | 115 ms | 15008 KB | Output is correct |
29 | Correct | 66 ms | 14072 KB | Output is correct |
30 | Correct | 117 ms | 14872 KB | Output is correct |
31 | Correct | 18 ms | 6416 KB | Output is correct |
32 | Correct | 73 ms | 14076 KB | Output is correct |
33 | Correct | 131 ms | 17268 KB | Output is correct |
34 | Correct | 93 ms | 14348 KB | Output is correct |
35 | Correct | 175 ms | 17264 KB | Output is correct |
36 | Correct | 82 ms | 13992 KB | Output is correct |
37 | Correct | 121 ms | 16632 KB | Output is correct |
38 | Correct | 106 ms | 15728 KB | Output is correct |
39 | Correct | 131 ms | 17056 KB | Output is correct |
40 | Correct | 124 ms | 16376 KB | Output is correct |
41 | Correct | 109 ms | 16072 KB | Output is correct |
42 | Correct | 150 ms | 17568 KB | Output is correct |
43 | Correct | 85 ms | 14748 KB | Output is correct |
44 | Correct | 175 ms | 17768 KB | Output is correct |
45 | Correct | 80 ms | 14456 KB | Output is correct |
46 | Correct | 110 ms | 16240 KB | Output is correct |