#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
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;
| ~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3007 ms |
87772 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3029 ms |
87820 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
96 ms |
24404 KB |
Output is correct |
2 |
Correct |
115 ms |
24020 KB |
Output is correct |
3 |
Correct |
12 ms |
24020 KB |
Output is correct |
4 |
Correct |
125 ms |
24112 KB |
Output is correct |
5 |
Correct |
153 ms |
24104 KB |
Output is correct |
6 |
Correct |
154 ms |
24020 KB |
Output is correct |
7 |
Incorrect |
161 ms |
24096 KB |
For each person outside the committee there should be someone in the committee who they dislike. |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3007 ms |
87772 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |