Submission #1090107

#TimeUsernameProblemLanguageResultExecution timeMemory
1090107Onur_IlgazNaboj (COCI22_naboj)C++17
110 / 110
142 ms25000 KiB
#include <bits/stdc++.h>
#define fast cin.tie(0)->sync_with_stdio(0);
#define int long long
#define inf ((int)1e18)
using namespace std;

int32_t main(){
	fast
	int n, m;
	cin >> n >> m;
	vector <vector <int> > adj(n + 1);
	vector <int> to(n + 1);
	for(int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		adj[b].push_back(a);
		to[a]++;
	}
	vector <int> ans, zeros;
	for(int i = 1; i <= n; i++) {
		if(!to[i]) {
			zeros.push_back(i);
		}
	}
	while(!zeros.empty()) {
		int node = zeros.back();
		ans.push_back(node);
		// cout << node << "\n";
		zeros.pop_back();
		for(auto it:adj[node]) {
			to[it]--;
			if(to[it] == 0) zeros.push_back(it);
		}
	}
	if(ans.size() != n) {
		cout << -1 << "\n";
		return 0;
	}
	cout << n << "\n";
	for(auto it:ans) {
		cout << it << " " << 1 << "\n";
	}
}

Compilation message (stderr)

naboj.cpp: In function 'int32_t main()':
naboj.cpp:35:16: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   35 |  if(ans.size() != n) {
      |     ~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...