Submission #782203

#TimeUsernameProblemLanguageResultExecution timeMemory
782203andecaandeciNaboj (COCI22_naboj)C++17
110 / 110
175 ms17768 KiB
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pii pair<int,int> #define pll pair<long long, long long> long long n,m,deg[200005]; vector<long long> vec[200005]; queue<long long> q; int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); long long tc,i,j; cin>>n>>m; for(i=1;i<=m;i++) { long long u,v; cin>>u>>v; deg[v]++; vec[u].push_back(v); } vector<long long> ans; for(i=1;i<=n;i++) { if(deg[i] == 0) { q.push(i); ans.push_back(i); } } while(!q.empty()) { long long node = q.front(); q.pop(); for(auto it : vec[node]) { deg[it]--; if(deg[it] == 0) { q.push(it); ans.push_back(it); } } } for(i=1;i<=n;i++) { if(deg[i] > 0) { break; } } if(i <= n) { cout<<-1<<'\n'; } else { cout<<ans.size()<<'\n'; for(auto it : ans) { cout<<it<<" 0\n"; } } }

Compilation message (stderr)

naboj.cpp: In function 'int main()':
naboj.cpp:17:15: warning: unused variable 'tc' [-Wunused-variable]
   17 |     long long tc,i,j;
      |               ^~
naboj.cpp:17:20: warning: unused variable 'j' [-Wunused-variable]
   17 |     long long tc,i,j;
      |                    ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...