#include "train.h"
#include<bits/stdc++.h>
using namespace std;
const int A = 1;
const int B = 0;
vector<int>g[(int)2e5+22], rg[(int)2e5+22];
int n, m;
int deg[(int)2e5+22];
queue<int>q;
vector<int>f(const int type, const vector<int>&S, const vector<int>&a, const vector<int>&answer) {
for (int i = 0 ; i < n ; ++ i) {
if (answer[i] != -1) {
deg[i] = -1;
continue;
}
deg[i] = 0;
for (int j : g[i]) {
deg[i] += answer[j] == -1;
}
}
for (int i : S) {
deg[i] = -1;
q.push(i);
}
while (q.size()) {
int v = q.front(); q.pop();
for (int from : rg[v]) if (deg[from] != -1) {
if (a[from] == type) {
deg[from] = -1;
q.push(from);
} else {
if (--deg[from] == 0) {
deg[from] = -1;
q.push(from);
}
}
}
}
vector<int>ans;
for (int i = 0 ; i < n ; ++ i) {
if (deg[i] == -1 && answer[i] == -1) {
ans.emplace_back(i);
}
}
return ans;
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
n = a.size();
m = u.size();
for (int i = 0 ; i < m ; ++ i) {
g[u[i]].emplace_back(v[i]);
rg[v[i]].emplace_back(u[i]);
}
vector<int>answer(n, -1);
vector<int>R;
vector<int>fa;
vector<int>nfa;
vector<int>infa;
vector<int>fb;
while (true) {
R.clear();
for (int i = 0 ; i < n ; ++ i) {
if (r[i] && answer[i] == -1) {
R.emplace_back(i);
}
}
if (R.empty()) {
for (int i = 0 ; i < n ; ++ i) {
if (answer[i] == -1) {
answer[i] = 0;
}
}
break;
}
fa = f(A, R, a, answer);
infa.assign(n, 0);
for (int i : fa) infa[i] = 1;
nfa.clear();
for (int i = 0 ; i < n ; ++ i) {
if (answer[i] == -1 && infa[i] == 0) {
nfa.emplace_back(i);
}
}
fb = f(B, nfa, a, answer);
if (fb.empty()) {
for (int i = 0 ; i < n ; ++ i) {
if (answer[i] == -1) {
answer[i] = 1;
}
}
break;
}
for (int i : fb) answer[i] = 0;
}
return answer;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
10292 KB |
Output is correct |
2 |
Correct |
17 ms |
10328 KB |
Output is correct |
3 |
Correct |
17 ms |
10292 KB |
Output is correct |
4 |
Correct |
16 ms |
10316 KB |
Output is correct |
5 |
Correct |
17 ms |
10316 KB |
Output is correct |
6 |
Correct |
16 ms |
10296 KB |
Output is correct |
7 |
Correct |
17 ms |
10348 KB |
Output is correct |
8 |
Correct |
17 ms |
10316 KB |
Output is correct |
9 |
Correct |
16 ms |
10268 KB |
Output is correct |
10 |
Correct |
14 ms |
10292 KB |
Output is correct |
11 |
Correct |
14 ms |
10296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9628 KB |
Output is correct |
2 |
Correct |
8 ms |
9652 KB |
Output is correct |
3 |
Correct |
7 ms |
9676 KB |
Output is correct |
4 |
Correct |
12 ms |
9616 KB |
Output is correct |
5 |
Correct |
7 ms |
9680 KB |
Output is correct |
6 |
Correct |
8 ms |
9676 KB |
Output is correct |
7 |
Correct |
16 ms |
9624 KB |
Output is correct |
8 |
Correct |
8 ms |
9608 KB |
Output is correct |
9 |
Correct |
8 ms |
9696 KB |
Output is correct |
10 |
Correct |
10 ms |
9624 KB |
Output is correct |
11 |
Correct |
7 ms |
9676 KB |
Output is correct |
12 |
Correct |
12 ms |
9704 KB |
Output is correct |
13 |
Correct |
9 ms |
9676 KB |
Output is correct |
14 |
Correct |
8 ms |
9720 KB |
Output is correct |
15 |
Correct |
11 ms |
9676 KB |
Output is correct |
16 |
Correct |
12 ms |
9696 KB |
Output is correct |
17 |
Correct |
11 ms |
9704 KB |
Output is correct |
18 |
Correct |
7 ms |
9676 KB |
Output is correct |
19 |
Correct |
8 ms |
9664 KB |
Output is correct |
20 |
Correct |
9 ms |
9676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
179 ms |
10700 KB |
Output is correct |
2 |
Correct |
455 ms |
10924 KB |
Output is correct |
3 |
Correct |
488 ms |
10712 KB |
Output is correct |
4 |
Correct |
17 ms |
10656 KB |
Output is correct |
5 |
Correct |
18 ms |
10532 KB |
Output is correct |
6 |
Correct |
17 ms |
10636 KB |
Output is correct |
7 |
Correct |
21 ms |
10528 KB |
Output is correct |
8 |
Correct |
19 ms |
10640 KB |
Output is correct |
9 |
Correct |
17 ms |
10640 KB |
Output is correct |
10 |
Correct |
18 ms |
10572 KB |
Output is correct |
11 |
Correct |
15 ms |
10588 KB |
Output is correct |
12 |
Correct |
17 ms |
10504 KB |
Output is correct |
13 |
Correct |
19 ms |
10572 KB |
Output is correct |
14 |
Correct |
21 ms |
10616 KB |
Output is correct |
15 |
Correct |
19 ms |
10572 KB |
Output is correct |
16 |
Correct |
16 ms |
10572 KB |
Output is correct |
17 |
Correct |
21 ms |
10604 KB |
Output is correct |
18 |
Correct |
613 ms |
10408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
10480 KB |
Output is correct |
2 |
Correct |
16 ms |
10444 KB |
Output is correct |
3 |
Correct |
22 ms |
10532 KB |
Output is correct |
4 |
Correct |
22 ms |
10668 KB |
Output is correct |
5 |
Correct |
17 ms |
10528 KB |
Output is correct |
6 |
Correct |
24 ms |
10564 KB |
Output is correct |
7 |
Correct |
20 ms |
10672 KB |
Output is correct |
8 |
Correct |
16 ms |
10520 KB |
Output is correct |
9 |
Correct |
21 ms |
10516 KB |
Output is correct |
10 |
Correct |
17 ms |
10540 KB |
Output is correct |
11 |
Correct |
21 ms |
10656 KB |
Output is correct |
12 |
Correct |
20 ms |
10516 KB |
Output is correct |
13 |
Correct |
18 ms |
10596 KB |
Output is correct |
14 |
Correct |
19 ms |
10556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
10524 KB |
Output is correct |
2 |
Correct |
20 ms |
10608 KB |
Output is correct |
3 |
Correct |
21 ms |
10596 KB |
Output is correct |
4 |
Correct |
19 ms |
10512 KB |
Output is correct |
5 |
Correct |
9 ms |
9676 KB |
Output is correct |
6 |
Correct |
16 ms |
10188 KB |
Output is correct |
7 |
Correct |
16 ms |
10220 KB |
Output is correct |
8 |
Correct |
16 ms |
10236 KB |
Output is correct |
9 |
Correct |
15 ms |
10296 KB |
Output is correct |
10 |
Correct |
9 ms |
9804 KB |
Output is correct |
11 |
Correct |
16 ms |
10188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
10292 KB |
Output is correct |
2 |
Correct |
17 ms |
10328 KB |
Output is correct |
3 |
Correct |
17 ms |
10292 KB |
Output is correct |
4 |
Correct |
16 ms |
10316 KB |
Output is correct |
5 |
Correct |
17 ms |
10316 KB |
Output is correct |
6 |
Correct |
16 ms |
10296 KB |
Output is correct |
7 |
Correct |
17 ms |
10348 KB |
Output is correct |
8 |
Correct |
17 ms |
10316 KB |
Output is correct |
9 |
Correct |
16 ms |
10268 KB |
Output is correct |
10 |
Correct |
14 ms |
10292 KB |
Output is correct |
11 |
Correct |
14 ms |
10296 KB |
Output is correct |
12 |
Correct |
7 ms |
9628 KB |
Output is correct |
13 |
Correct |
8 ms |
9652 KB |
Output is correct |
14 |
Correct |
7 ms |
9676 KB |
Output is correct |
15 |
Correct |
12 ms |
9616 KB |
Output is correct |
16 |
Correct |
7 ms |
9680 KB |
Output is correct |
17 |
Correct |
8 ms |
9676 KB |
Output is correct |
18 |
Correct |
16 ms |
9624 KB |
Output is correct |
19 |
Correct |
8 ms |
9608 KB |
Output is correct |
20 |
Correct |
8 ms |
9696 KB |
Output is correct |
21 |
Correct |
10 ms |
9624 KB |
Output is correct |
22 |
Correct |
7 ms |
9676 KB |
Output is correct |
23 |
Correct |
12 ms |
9704 KB |
Output is correct |
24 |
Correct |
9 ms |
9676 KB |
Output is correct |
25 |
Correct |
8 ms |
9720 KB |
Output is correct |
26 |
Correct |
11 ms |
9676 KB |
Output is correct |
27 |
Correct |
12 ms |
9696 KB |
Output is correct |
28 |
Correct |
11 ms |
9704 KB |
Output is correct |
29 |
Correct |
7 ms |
9676 KB |
Output is correct |
30 |
Correct |
8 ms |
9664 KB |
Output is correct |
31 |
Correct |
9 ms |
9676 KB |
Output is correct |
32 |
Correct |
179 ms |
10700 KB |
Output is correct |
33 |
Correct |
455 ms |
10924 KB |
Output is correct |
34 |
Correct |
488 ms |
10712 KB |
Output is correct |
35 |
Correct |
17 ms |
10656 KB |
Output is correct |
36 |
Correct |
18 ms |
10532 KB |
Output is correct |
37 |
Correct |
17 ms |
10636 KB |
Output is correct |
38 |
Correct |
21 ms |
10528 KB |
Output is correct |
39 |
Correct |
19 ms |
10640 KB |
Output is correct |
40 |
Correct |
17 ms |
10640 KB |
Output is correct |
41 |
Correct |
18 ms |
10572 KB |
Output is correct |
42 |
Correct |
15 ms |
10588 KB |
Output is correct |
43 |
Correct |
17 ms |
10504 KB |
Output is correct |
44 |
Correct |
19 ms |
10572 KB |
Output is correct |
45 |
Correct |
21 ms |
10616 KB |
Output is correct |
46 |
Correct |
19 ms |
10572 KB |
Output is correct |
47 |
Correct |
16 ms |
10572 KB |
Output is correct |
48 |
Correct |
21 ms |
10604 KB |
Output is correct |
49 |
Correct |
613 ms |
10408 KB |
Output is correct |
50 |
Correct |
19 ms |
10480 KB |
Output is correct |
51 |
Correct |
16 ms |
10444 KB |
Output is correct |
52 |
Correct |
22 ms |
10532 KB |
Output is correct |
53 |
Correct |
22 ms |
10668 KB |
Output is correct |
54 |
Correct |
17 ms |
10528 KB |
Output is correct |
55 |
Correct |
24 ms |
10564 KB |
Output is correct |
56 |
Correct |
20 ms |
10672 KB |
Output is correct |
57 |
Correct |
16 ms |
10520 KB |
Output is correct |
58 |
Correct |
21 ms |
10516 KB |
Output is correct |
59 |
Correct |
17 ms |
10540 KB |
Output is correct |
60 |
Correct |
21 ms |
10656 KB |
Output is correct |
61 |
Correct |
20 ms |
10516 KB |
Output is correct |
62 |
Correct |
18 ms |
10596 KB |
Output is correct |
63 |
Correct |
19 ms |
10556 KB |
Output is correct |
64 |
Correct |
20 ms |
10524 KB |
Output is correct |
65 |
Correct |
20 ms |
10608 KB |
Output is correct |
66 |
Correct |
21 ms |
10596 KB |
Output is correct |
67 |
Correct |
19 ms |
10512 KB |
Output is correct |
68 |
Correct |
9 ms |
9676 KB |
Output is correct |
69 |
Correct |
16 ms |
10188 KB |
Output is correct |
70 |
Correct |
16 ms |
10220 KB |
Output is correct |
71 |
Correct |
16 ms |
10236 KB |
Output is correct |
72 |
Correct |
15 ms |
10296 KB |
Output is correct |
73 |
Correct |
9 ms |
9804 KB |
Output is correct |
74 |
Correct |
16 ms |
10188 KB |
Output is correct |
75 |
Correct |
256 ms |
10708 KB |
Output is correct |
76 |
Correct |
391 ms |
10712 KB |
Output is correct |
77 |
Correct |
551 ms |
10716 KB |
Output is correct |
78 |
Correct |
532 ms |
10716 KB |
Output is correct |
79 |
Correct |
568 ms |
10716 KB |
Output is correct |
80 |
Correct |
17 ms |
10656 KB |
Output is correct |
81 |
Correct |
19 ms |
10564 KB |
Output is correct |
82 |
Correct |
24 ms |
10600 KB |
Output is correct |
83 |
Correct |
23 ms |
10524 KB |
Output is correct |
84 |
Correct |
19 ms |
10596 KB |
Output is correct |
85 |
Correct |
20 ms |
10700 KB |
Output is correct |
86 |
Correct |
23 ms |
10524 KB |
Output is correct |
87 |
Correct |
21 ms |
10572 KB |
Output is correct |
88 |
Correct |
22 ms |
10528 KB |
Output is correct |
89 |
Correct |
17 ms |
10636 KB |
Output is correct |
90 |
Correct |
34 ms |
10620 KB |
Output is correct |
91 |
Correct |
29 ms |
10652 KB |
Output is correct |
92 |
Correct |
46 ms |
10664 KB |
Output is correct |
93 |
Correct |
47 ms |
10644 KB |
Output is correct |
94 |
Correct |
40 ms |
10648 KB |
Output is correct |
95 |
Correct |
45 ms |
10572 KB |
Output is correct |
96 |
Correct |
123 ms |
10596 KB |
Output is correct |
97 |
Correct |
560 ms |
10680 KB |
Output is correct |
98 |
Correct |
773 ms |
10668 KB |
Output is correct |
99 |
Correct |
777 ms |
10648 KB |
Output is correct |
100 |
Correct |
614 ms |
10416 KB |
Output is correct |