Submission #644394

#TimeUsernameProblemLanguageResultExecution timeMemory
644394IwanttobreakfreeNaboj (COCI22_naboj)C++17
110 / 110
392 ms21184 KiB
#include <iostream> #include <vector> #include <queue> using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<int>> g (n,vector<int>()); while (m--) { int a, b; cin >> a >> b; a--;b--; g[b].push_back (a); } vector<int> cnt (n); for (int i = 0; i < n; ++i) for (int x :g[i]) cnt[x]++; queue<int> q; for (int i = 0; i < n; ++i) if(!cnt[i]) q.push(i); vector<int> ans; while (!q.empty()) { int u = q.front(); ans.push_back (u); q.pop(); for (int v:g[u]){ cnt[v]--; if (!cnt[v])q.push (v); } } if (ans.size() == n) { cout << n << '\n'; for (auto x : ans) cout << x+1 << ' ' << 1 << '\n'; } else cout << -1; }

Compilation message (stderr)

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