Submission #960241

#TimeUsernameProblemLanguageResultExecution timeMemory
960241Darren0724Povjerenstvo (COI22_povjerenstvo)C++17
0 / 100
46 ms28628 KiB
#include <bits/stdc++.h> using namespace std; #define LCBorz ios_base::sync_with_stdio(false); cin.tie(0); //#define int long long #define all(x) x.begin(), x.end() #define endl '\n' const int N=200005; int n,m; vector<int> vis(N,-1),out(N,0); vector<int> adj[N]; int32_t main() { LCBorz; cin>>n>>m; for(int i=0;i<m;i++){ int a,b;cin>>a>>b; out[a]++; adj[b].push_back(a); } vector<int> ans1(N,-1); queue<int> q; for(int i=1;i<=n;i++){ if(out[i]==0){ ans1[i]=1; q.push(i); } } while(q.size()){ int p=q.front(); q.pop(); ans1[p]=1; for(int j:adj[p]){ if(ans1[j]==1){ cout<<-1<<endl; return 0; } if(ans1[j]==-1){ for(int j1:adj[j]){ out[j1]--; if(out[j1]==0){ q.push(j1); } } } ans1[j]=0; } } vector<int> ans; for(int i=1;i<=n;i++){ if(ans1[i]==1){ ans.push_back(i); } } cout<<ans.size()<<endl; for(int j:ans){ cout<<j<<' '; } cout<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...