# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
788220 | Username4132 | Povjerenstvo (COI22_povjerenstvo) | C++14 | 211 ms | 73168 KiB |
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<iostream>
#include<vector>
using namespace std;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define PB push_back
const int MAXN = 500010;
bool yes[MAXN], vis[MAXN];
int n, m, ans;
vector<int> g[MAXN];
void dfs(int v){
vis[v]=true;
bool res=false;
for(int to:g[v]){
if(!vis[to]) dfs(to);
res|=yes[to];
}
yes[v]=!res;
}
int main(){
scanf("%d %d", &n, &m);
forn(i, m){
int a, b; scanf("%d %d", &a, &b); --a, --b;
g[a].PB(b);
}
forn(i, n) if(!vis[i]) dfs(i);
forn(i, n) ans+=yes[i];
printf("%d\n", ans);
forn(i, n) if(yes[i]) printf("%d ", i+1);
printf("\n");
}
Compilation message (stderr)
# | 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... |