Submission #983709

#TimeUsernameProblemLanguageResultExecution timeMemory
983709Sandarach151Naboj (COCI22_naboj)C++17
110 / 110
181 ms20204 KiB
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector<int> down[n]; vector<int> topsort; int edge[n] = { 0 }; for(int i=0; i<m; i++){ int a, b; cin >> a >> b; a--; b--; down[a].push_back(b); edge[b]++; } queue<int> noedge; for(int i=0; i<n; i++){ if(edge[i]==0){ noedge.push(i); } } while(!noedge.empty()){ int cur = noedge.front(); noedge.pop(); topsort.push_back(cur); for(auto u : down[cur]){ edge[u]--; if(edge[u]==0){ noedge.push(u); } } } // for(auto u : topsort){ // cout << u << ' '; // } if(topsort.size()!=n){ cout << -1 << '\n'; } else{ cout << n-1 << '\n'; for(int i=n-2; i>=0; i--){ cout << topsort[i]+1 << ' ' << 1 << '\n'; } } return 0; }

Compilation message (stderr)

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