Submission #789049

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