Submission #788254

#TimeUsernameProblemLanguageResultExecution timeMemory
788254Username4132Povjerenstvo (COI22_povjerenstvo)C++14
0 / 100
3029 ms87820 KiB
#include<iostream> #include<vector> #include<algorithm> #include<cassert> using namespace std; #define forn(i, n) for(int i=0; i<(int)n; ++i) #define PB push_back const int MAXN = 500010; int n, m, cn; bool vis[MAXN], del[MAXN], ans[MAXN], allow[MAXN]; vector<int> g[MAXN], gi[MAXN], order, lst; void dfs1(int v){ vis[v]=true; for(int to:g[v]) if(!vis[to] && !del[to]) dfs1(to); order.PB(v); } void dfs2(int v){ vis[v]=true; for(int to:gi[v]) if(!vis[to] && !del[to]) dfs2(to); lst.PB(v); } void dfs3(int v, bool flag){ vis[v]=true; ans[v]=flag; for(int to:gi[v]) if(!del[to]){ del[to]=true; if(!vis[to] && allow[to]) dfs3(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){ order.clear(); lst.clear(); forn(i, n) vis[i]=false; forn(i, n) if(!vis[i] && !del[i]) dfs1(i); if(order.empty()) break; reverse(order.begin(), order.end()); forn(i, n) vis[i]=false; for(int el:order) if(!vis[el]) lst.clear(), dfs2(el); int v = lst.back(); assert(!del[v]); del[v]=true; forn(i, n) vis[i]=allow[i]=false; for(int el:lst) allow[el]=true; dfs3(v, true); } 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:36:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:38:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         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...