# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
782195 | 2023-07-13T16:15:04 Z | devariaota | Naboj (COCI22_naboj) | C++17 | 519 ms | 40088 KB |
#include<bits/stdc++.h> #define sherina ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define pb push_back #define int long long #define INF 1e18 using namespace std; int n , m , a[500005] , b[500005] , jmlhbapa[500005]; vector < int > adj[500005]; vector < pair < int , int > > ans; void dfs(){ queue < int > q; for(int i = 1 ; i <= n ; i++){ if(jmlhbapa[i] == 0){ q.push(i); ans.pb(make_pair(i , 0)); } } while(!q.empty()){ int u = q.front(); q.pop(); //cout << u << endl; for(int i : adj[u]){ jmlhbapa[i]--; if(jmlhbapa[i] == 0){ ans.pb(make_pair(i , 0)); q.push(i); } } } } signed main(){ cin >> n >> m; for(int i = 1 ; i <= m ; i++){ cin >> a[i] >> b[i]; adj[a[i]].pb(b[i]); jmlhbapa[b[i]]++; } dfs(); bool bs = true; for(int i = 1 ; i <= n ; i++){ if(jmlhbapa[i] > 0) bs = false; } if(!bs){ cout << "-1" << endl; return 0; } cout << ans.size() << endl; for(int i = 0 ; i < ans.size() ; i++){ cout << ans[i].first << " " << ans[i].second << endl; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 12048 KB | Output is correct |
2 | Correct | 7 ms | 12044 KB | Output is correct |
3 | Correct | 6 ms | 12052 KB | Output is correct |
4 | Correct | 6 ms | 11988 KB | Output is correct |
5 | Correct | 6 ms | 12052 KB | Output is correct |
6 | Correct | 6 ms | 11988 KB | Output is correct |
7 | Correct | 6 ms | 11976 KB | Output is correct |
8 | Correct | 6 ms | 12056 KB | Output is correct |
9 | Correct | 6 ms | 12048 KB | Output is correct |
10 | Correct | 6 ms | 12056 KB | Output is correct |
11 | Correct | 6 ms | 12048 KB | Output is correct |
12 | Correct | 6 ms | 12052 KB | Output is correct |
13 | Correct | 6 ms | 12056 KB | Output is correct |
14 | Correct | 5 ms | 11988 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 341 ms | 29144 KB | Output is correct |
2 | Correct | 333 ms | 29052 KB | Output is correct |
3 | Correct | 171 ms | 20828 KB | Output is correct |
4 | Correct | 336 ms | 29028 KB | Output is correct |
5 | Correct | 335 ms | 29064 KB | Output is correct |
6 | Correct | 354 ms | 29108 KB | Output is correct |
7 | Correct | 348 ms | 29012 KB | Output is correct |
8 | Correct | 275 ms | 25836 KB | Output is correct |
9 | Correct | 336 ms | 29120 KB | Output is correct |
10 | Correct | 354 ms | 29004 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 12048 KB | Output is correct |
2 | Correct | 7 ms | 12044 KB | Output is correct |
3 | Correct | 6 ms | 12052 KB | Output is correct |
4 | Correct | 6 ms | 11988 KB | Output is correct |
5 | Correct | 6 ms | 12052 KB | Output is correct |
6 | Correct | 6 ms | 11988 KB | Output is correct |
7 | Correct | 6 ms | 11976 KB | Output is correct |
8 | Correct | 6 ms | 12056 KB | Output is correct |
9 | Correct | 6 ms | 12048 KB | Output is correct |
10 | Correct | 6 ms | 12056 KB | Output is correct |
11 | Correct | 6 ms | 12048 KB | Output is correct |
12 | Correct | 6 ms | 12052 KB | Output is correct |
13 | Correct | 6 ms | 12056 KB | Output is correct |
14 | Correct | 5 ms | 11988 KB | Output is correct |
15 | Correct | 341 ms | 29144 KB | Output is correct |
16 | Correct | 333 ms | 29052 KB | Output is correct |
17 | Correct | 171 ms | 20828 KB | Output is correct |
18 | Correct | 336 ms | 29028 KB | Output is correct |
19 | Correct | 335 ms | 29064 KB | Output is correct |
20 | Correct | 354 ms | 29108 KB | Output is correct |
21 | Correct | 348 ms | 29012 KB | Output is correct |
22 | Correct | 275 ms | 25836 KB | Output is correct |
23 | Correct | 336 ms | 29120 KB | Output is correct |
24 | Correct | 354 ms | 29004 KB | Output is correct |
25 | Correct | 212 ms | 31132 KB | Output is correct |
26 | Correct | 189 ms | 30068 KB | Output is correct |
27 | Correct | 216 ms | 31868 KB | Output is correct |
28 | Correct | 316 ms | 35600 KB | Output is correct |
29 | Correct | 147 ms | 30120 KB | Output is correct |
30 | Correct | 282 ms | 35212 KB | Output is correct |
31 | Correct | 42 ms | 15640 KB | Output is correct |
32 | Correct | 344 ms | 29100 KB | Output is correct |
33 | Correct | 476 ms | 38452 KB | Output is correct |
34 | Correct | 363 ms | 30076 KB | Output is correct |
35 | Correct | 466 ms | 38720 KB | Output is correct |
36 | Correct | 342 ms | 28792 KB | Output is correct |
37 | Correct | 479 ms | 36552 KB | Output is correct |
38 | Correct | 414 ms | 33748 KB | Output is correct |
39 | Correct | 519 ms | 38220 KB | Output is correct |
40 | Correct | 452 ms | 35408 KB | Output is correct |
41 | Correct | 446 ms | 35240 KB | Output is correct |
42 | Correct | 493 ms | 39684 KB | Output is correct |
43 | Correct | 363 ms | 30916 KB | Output is correct |
44 | Correct | 482 ms | 40088 KB | Output is correct |
45 | Correct | 366 ms | 29840 KB | Output is correct |
46 | Correct | 445 ms | 35380 KB | Output is correct |