Submission #967504

# Submission time Handle Problem Language Result Execution time Memory
967504 2024-04-22T09:28:34 Z Isam Naboj (COCI22_naboj) C++17
110 / 110
163 ms 21216 KB
#include<bits/stdc++.h>
using namespace std;

int n, m, cnt[200002];

vector<int> g[200002], em;

queue<int> q;

signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m;
	for(register int i = 1, a, b; i <= m; ++i){
		cin >> a >> b;
		
		g[b].emplace_back(a);
		
		cnt[a]++;
	}
	
	for(register int i = 1; i <= n; ++i){
		if(!cnt[i]) q.push(i);
	}
	
	while(!q.empty()){
		
		int cur = q.front();
		q.pop();
		
		em.emplace_back(cur);
		
		for(const int &to : g[cur]){
			
			cnt[to]--;
			
			if(!cnt[to]) q.push(to);
			
		}
	}
	
	if((int)em.size() ^ n){
		cout << -1 << '\n';
	}else{
		cout << n << '\n';
		for(const int &to : em) cout << to << ' ' << 1 << '\n';
	}
	
	
	return 0;
}

Compilation message

naboj.cpp: In function 'int main()':
naboj.cpp:13:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   13 |  for(register int i = 1, a, b; i <= m; ++i){
      |                   ^
naboj.cpp:13:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   13 |  for(register int i = 1, a, b; i <= m; ++i){
      |                          ^
naboj.cpp:13:29: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   13 |  for(register int i = 1, a, b; i <= m; ++i){
      |                             ^
naboj.cpp:21:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   21 |  for(register int i = 1; i <= n; ++i){
      |                   ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 1 ms 5156 KB Output is correct
11 Correct 1 ms 4952 KB Output is correct
12 Correct 1 ms 4952 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 15344 KB Output is correct
2 Correct 70 ms 15304 KB Output is correct
3 Correct 35 ms 10404 KB Output is correct
4 Correct 70 ms 15568 KB Output is correct
5 Correct 72 ms 15420 KB Output is correct
6 Correct 81 ms 15472 KB Output is correct
7 Correct 75 ms 15516 KB Output is correct
8 Correct 56 ms 13180 KB Output is correct
9 Correct 69 ms 15512 KB Output is correct
10 Correct 73 ms 15396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 1 ms 5156 KB Output is correct
11 Correct 1 ms 4952 KB Output is correct
12 Correct 1 ms 4952 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 82 ms 15344 KB Output is correct
16 Correct 70 ms 15304 KB Output is correct
17 Correct 35 ms 10404 KB Output is correct
18 Correct 70 ms 15568 KB Output is correct
19 Correct 72 ms 15420 KB Output is correct
20 Correct 81 ms 15472 KB Output is correct
21 Correct 75 ms 15516 KB Output is correct
22 Correct 56 ms 13180 KB Output is correct
23 Correct 69 ms 15512 KB Output is correct
24 Correct 73 ms 15396 KB Output is correct
25 Correct 76 ms 15232 KB Output is correct
26 Correct 63 ms 15484 KB Output is correct
27 Correct 87 ms 16464 KB Output is correct
28 Correct 92 ms 18000 KB Output is correct
29 Correct 57 ms 15076 KB Output is correct
30 Correct 91 ms 18000 KB Output is correct
31 Correct 15 ms 7004 KB Output is correct
32 Correct 84 ms 18008 KB Output is correct
33 Correct 133 ms 20712 KB Output is correct
34 Correct 80 ms 18028 KB Output is correct
35 Correct 124 ms 20796 KB Output is correct
36 Correct 89 ms 17796 KB Output is correct
37 Correct 117 ms 20172 KB Output is correct
38 Correct 108 ms 19144 KB Output is correct
39 Correct 163 ms 20656 KB Output is correct
40 Correct 108 ms 19664 KB Output is correct
41 Correct 122 ms 19704 KB Output is correct
42 Correct 159 ms 21192 KB Output is correct
43 Correct 89 ms 18428 KB Output is correct
44 Correct 130 ms 21216 KB Output is correct
45 Correct 77 ms 18012 KB Output is correct
46 Correct 112 ms 19916 KB Output is correct