Submission #788233

#TimeUsernameProblemLanguageResultExecution timeMemory
788233Username4132Povjerenstvo (COI22_povjerenstvo)C++14
0 / 100
3084 ms80568 KiB
#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 del[MAXN], vis[MAXN], ans[MAXN]; int n, m, cn; vector<int> g[MAXN], gi[MAXN]; void dfs(int v, bool flag){ vis[v]=true; ans[v]=flag; for(int to:gi[v]){ del[to]=true; if(!vis[to]) dfs(to, !flag); } } int main(){ scanf("%d %d", &n, &m); forn(i, m){ int a, b; scanf("%d %d", &a, &b); --a, --b; g[a].PB(b), gi[b].PB(a); } while(true){ int v=-1; forn(i, n) if(!del[i]) v=i; if(v==-1) break; forn(i, n) vis[i]=false; while(!g[v].empty() && !vis[g[v].back()]) v=g[v].back(), vis[v]=true; forn(i, n) vis[v]=false; del[v]=true; dfs(v, true); forn(i, n){ if(del[i]) g[i].clear(), gi[i].clear(); else{ vector<int> keep, ki; for(int el:g[i]) if(!del[el]) keep.PB(el); for(int el:gi[i]) if(!del[el]) ki.PB(el); swap(g[i], keep); swap(gi[i], ki); } } } forn(i, n) cn+=ans[i]; printf("%d\n", cn); forn(i, n) if(ans[i]) printf("%d ", i+1); }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:24:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         int a, b; scanf("%d %d", &a, &b); --a, --b;
      |                   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...