Submission #704918

#TimeUsernameProblemLanguageResultExecution timeMemory
704918guagua0407Naboj (COCI22_naboj)C++17
110 / 110
272 ms21384 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define f first #define s second #define all(x) x.begin(),x.end() int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m; cin>>n>>m; vector<int> in(n,0); vector<bool> visited(n,false); vector<int> adj[n],adjr[n]; for(int i=0;i<m;i++){ int a,b; cin>>a>>b; a--; b--; in[a]++; adj[b].push_back(a); } queue<int> q; for(int i=0;i<n;i++){ if(in[i]==0){ visited[i]=true; q.push(i); } } vector<pair<int,int>> ans; while(!q.empty()){ int v=q.front(); q.pop(); ans.push_back({v,0}); for(auto u:adj[v]){ if(visited[u]){ cout<<-1; return 0; } in[u]--; if(in[u]==0){ visited[u]=true; q.push(u); } } } if(ans.size()!=n){ cout<<-1; return 0; } cout<<ans.size()<<'\n'; reverse(all(ans)); for(auto v:ans){ cout<<v.f+1<<' '<<v.s<<'\n'; } }

Compilation message (stderr)

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