#include <bits/stdc++.h>
using namespace std;
#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;
void usaco()
{
freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
// freopen("problem.out", "w", stdout);
}
int main() {
// usaco();
int n, m;
scd(n);
scd(m);
vvi gr(n+1), rg(n+1);
vi outdeg(n+1);
frange(i, m) {
int a, b;
scd(a);
scd(b);
outdeg[a]++;
gr[a].pb(b);
rg[b].pb(a);
}
vb vis(n+1);
vb pick(n+1);
queue<pair<int, bool>> q;
forr(i, 1, n+1) {
if(outdeg[i] == 0) q.push(mp(i, true));
}
while(q.size()) {
auto p = q.front();
q.pop();
if(vis[p.f]) continue;
vis[p.f] = true;
pick[p.f] = p.s;
if(p.s) {
for(auto e : gr[p.f]) {
q.push(mp(e, !p.s));
}
for(auto e : rg[p.f]) {
q.push(mp(e, !p.s));
}
}
else {
for(auto e : rg[p.f]) {
outdeg[e]--;
if(outdeg[e] == 0) q.push(mp(e, !p.s));
}
}
}
forr(i, 1, n+1) {
if(!vis[i]) {
q.push(mp(i, true));
while(q.size()) {
auto p = q.front();
q.pop();
if(vis[p.f]) continue;
vis[p.f] = true;
pick[p.f] = p.s;
if(p.s) {
for(auto e : gr[p.f]) {
q.push(mp(e, !p.s));
}
for(auto e : rg[p.f]) {
q.push(mp(e, !p.s));
}
}
else {
for(auto e : rg[p.f]) {
outdeg[e]--;
if(outdeg[e] == 0) q.push(mp(e, !p.s));
}
}
}
}
}
vi out;
forr(i, 1, n+1) {
if(pick[i]) out.pb(i);
}
printf("%d\n", (int)out.size());
for(auto e : out) printf("%d ", e);
}
Compilation message
Main.cpp: In function 'void usaco()':
Main.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
Main.cpp:37:5: note: in expansion of macro 'scd'
37 | scd(n);
| ^~~
Main.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
Main.cpp:38:5: note: in expansion of macro 'scd'
38 | scd(m);
| ^~~
Main.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
Main.cpp:44:9: note: in expansion of macro 'scd'
44 | scd(a);
| ^~~
Main.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
Main.cpp:45:9: note: in expansion of macro 'scd'
45 | scd(b);
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
139 ms |
57248 KB |
Output is correct |
2 |
Correct |
146 ms |
57028 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
49 ms |
33872 KB |
Output is correct |
5 |
Correct |
85 ms |
46060 KB |
Output is correct |
6 |
Correct |
132 ms |
48916 KB |
Output is correct |
7 |
Correct |
96 ms |
47028 KB |
Output is correct |
8 |
Correct |
135 ms |
48184 KB |
Output is correct |
9 |
Correct |
263 ms |
52660 KB |
Output is correct |
10 |
Correct |
206 ms |
49548 KB |
Output is correct |
11 |
Correct |
263 ms |
50452 KB |
Output is correct |
12 |
Correct |
273 ms |
45096 KB |
Output is correct |
13 |
Correct |
217 ms |
51392 KB |
Output is correct |
14 |
Correct |
207 ms |
52536 KB |
Output is correct |
15 |
Correct |
196 ms |
52940 KB |
Output is correct |
16 |
Correct |
181 ms |
53064 KB |
Output is correct |
17 |
Correct |
38 ms |
5980 KB |
Output is correct |
18 |
Correct |
68 ms |
9508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
146 ms |
57456 KB |
Output is correct |
2 |
Correct |
141 ms |
49860 KB |
Output is correct |
3 |
Correct |
99 ms |
44996 KB |
Output is correct |
4 |
Correct |
263 ms |
49688 KB |
Output is correct |
5 |
Correct |
332 ms |
50360 KB |
Output is correct |
6 |
Correct |
241 ms |
47576 KB |
Output is correct |
7 |
Correct |
225 ms |
47868 KB |
Output is correct |
8 |
Correct |
208 ms |
47784 KB |
Output is correct |
9 |
Correct |
192 ms |
47948 KB |
Output is correct |
10 |
Correct |
39 ms |
3736 KB |
Output is correct |
11 |
Correct |
33 ms |
6356 KB |
Output is correct |
12 |
Correct |
34 ms |
6492 KB |
Output is correct |
13 |
Correct |
134 ms |
55048 KB |
Output is correct |
14 |
Correct |
140 ms |
58200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
860 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
860 KB |
Output is correct |
4 |
Correct |
2 ms |
860 KB |
Output is correct |
5 |
Correct |
3 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
856 KB |
Output is correct |
8 |
Correct |
2 ms |
856 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
860 KB |
Output is correct |
13 |
Correct |
2 ms |
860 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
808 KB |
Output is correct |
16 |
Correct |
2 ms |
860 KB |
Output is correct |
17 |
Correct |
2 ms |
860 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
139 ms |
57248 KB |
Output is correct |
2 |
Correct |
146 ms |
57028 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
49 ms |
33872 KB |
Output is correct |
5 |
Correct |
85 ms |
46060 KB |
Output is correct |
6 |
Correct |
132 ms |
48916 KB |
Output is correct |
7 |
Correct |
96 ms |
47028 KB |
Output is correct |
8 |
Correct |
135 ms |
48184 KB |
Output is correct |
9 |
Correct |
263 ms |
52660 KB |
Output is correct |
10 |
Correct |
206 ms |
49548 KB |
Output is correct |
11 |
Correct |
263 ms |
50452 KB |
Output is correct |
12 |
Correct |
273 ms |
45096 KB |
Output is correct |
13 |
Correct |
217 ms |
51392 KB |
Output is correct |
14 |
Correct |
207 ms |
52536 KB |
Output is correct |
15 |
Correct |
196 ms |
52940 KB |
Output is correct |
16 |
Correct |
181 ms |
53064 KB |
Output is correct |
17 |
Correct |
38 ms |
5980 KB |
Output is correct |
18 |
Correct |
68 ms |
9508 KB |
Output is correct |
19 |
Correct |
146 ms |
57456 KB |
Output is correct |
20 |
Correct |
141 ms |
49860 KB |
Output is correct |
21 |
Correct |
99 ms |
44996 KB |
Output is correct |
22 |
Correct |
263 ms |
49688 KB |
Output is correct |
23 |
Correct |
332 ms |
50360 KB |
Output is correct |
24 |
Correct |
241 ms |
47576 KB |
Output is correct |
25 |
Correct |
225 ms |
47868 KB |
Output is correct |
26 |
Correct |
208 ms |
47784 KB |
Output is correct |
27 |
Correct |
192 ms |
47948 KB |
Output is correct |
28 |
Correct |
39 ms |
3736 KB |
Output is correct |
29 |
Correct |
33 ms |
6356 KB |
Output is correct |
30 |
Correct |
34 ms |
6492 KB |
Output is correct |
31 |
Correct |
134 ms |
55048 KB |
Output is correct |
32 |
Correct |
140 ms |
58200 KB |
Output is correct |
33 |
Correct |
2 ms |
860 KB |
Output is correct |
34 |
Correct |
2 ms |
860 KB |
Output is correct |
35 |
Correct |
1 ms |
860 KB |
Output is correct |
36 |
Correct |
2 ms |
860 KB |
Output is correct |
37 |
Correct |
3 ms |
860 KB |
Output is correct |
38 |
Correct |
2 ms |
860 KB |
Output is correct |
39 |
Correct |
2 ms |
856 KB |
Output is correct |
40 |
Correct |
2 ms |
856 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
2 ms |
860 KB |
Output is correct |
45 |
Correct |
2 ms |
860 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
2 ms |
808 KB |
Output is correct |
48 |
Correct |
2 ms |
860 KB |
Output is correct |
49 |
Correct |
2 ms |
860 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
1 ms |
604 KB |
Output is correct |
52 |
Correct |
142 ms |
63740 KB |
Output is correct |
53 |
Correct |
165 ms |
53880 KB |
Output is correct |
54 |
Correct |
100 ms |
48960 KB |
Output is correct |
55 |
Correct |
251 ms |
55604 KB |
Output is correct |
56 |
Correct |
336 ms |
56912 KB |
Output is correct |
57 |
Correct |
234 ms |
54008 KB |
Output is correct |
58 |
Correct |
234 ms |
54312 KB |
Output is correct |
59 |
Correct |
217 ms |
54348 KB |
Output is correct |
60 |
Correct |
44 ms |
6224 KB |
Output is correct |
61 |
Correct |
33 ms |
7772 KB |
Output is correct |
62 |
Correct |
34 ms |
8048 KB |
Output is correct |
63 |
Correct |
138 ms |
61144 KB |
Output is correct |
64 |
Correct |
139 ms |
62704 KB |
Output is correct |
65 |
Correct |
38 ms |
8364 KB |
Output is correct |
66 |
Correct |
290 ms |
52792 KB |
Output is correct |
67 |
Correct |
219 ms |
53580 KB |
Output is correct |
68 |
Correct |
212 ms |
52768 KB |
Output is correct |
69 |
Correct |
39 ms |
5864 KB |
Output is correct |
70 |
Correct |
111 ms |
20964 KB |
Output is correct |