This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 5e5 + 5;
vector<int> adj[N], adjrev[N];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n, m;
cin>>n>>m;
for(int i = 0; i < m; i++){
int u, v;
cin>>u>>v;
adj[u].pb(v);
adjrev[v].pb(u);
}
vector<int> ans;
vector<int> nope(n+1);
for(int i = 1; i <= n; i++){
if(!nope[i]){
ans.pb(i);
for(auto itr: adjrev[i]) nope[itr] = 1;
for(auto itr: adj[i]) nope[itr] = 1;
}
}
cout<<ans.size()<<endl;
for(auto itr: ans){
cout<<itr<<" ";
}
cout<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |