Submission #782223

#TimeUsernameProblemLanguageResultExecution timeMemory
782223christinelynnNaboj (COCI22_naboj)C++17
110 / 110
552 ms19316 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n,m; vector <ll> al[200005]; ll deg[200005]; int main(){ cin>>n>>m; queue<ll> q; for (int i=1;i<=m;i++){ ll a,b; cin>>a>>b; al[a].push_back(b); deg[b]++; } vector <pair<ll,ll>> ans; for (int i=1;i<=n;i++){ if (deg[i]==0) { q.push(i); ans.push_back({i,0}); } } while(!q.empty()){ ll u=q.front(); q.pop(); for (auto z:al[u]){ deg[z]--; if (deg[z]==0){ ans.push_back({z,0}); q.push(z); } } } if (ans.size()!=n) cout<<-1; else{ cout<<ans.size()<<endl; for (auto z:ans){ cout<<z.first<<" "<<z.second<<endl; } } }

Compilation message (stderr)

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