Submission #852284

#TimeUsernameProblemLanguageResultExecution timeMemory
852284Trisanu_DasNaboj (COCI22_naboj)C++17
110 / 110
248 ms20268 KiB
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector<int> deg(n + 1), adj[n + 1], topo; int a, b; while(m--){ cin >> a >> b; deg[b]++; adj[a].push_back(b); } queue<int> q; for(int i = 1; i <= n; i++) if(deg[i] == 0) q.push(i); while(!q.empty()){ int u = q.front(); q.pop(); topo.push_back(u); for(auto v : adj[u]){ deg[v]--; if(deg[v] == 0) q.push(v); } } if(topo.size() != n) cout << -1; else { cout << n << '\n'; for(auto x : topo) cout << x << ' ' << 0 << '\n'; } }

Compilation message (stderr)

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