#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 |
19 ms |
10448 KB |
Output is correct |
2 |
Correct |
18 ms |
10336 KB |
Output is correct |
3 |
Correct |
18 ms |
10408 KB |
Output is correct |
4 |
Correct |
15 ms |
10432 KB |
Output is correct |
5 |
Correct |
14 ms |
10436 KB |
Output is correct |
6 |
Correct |
14 ms |
10424 KB |
Output is correct |
7 |
Correct |
16 ms |
10444 KB |
Output is correct |
8 |
Correct |
14 ms |
10332 KB |
Output is correct |
9 |
Correct |
13 ms |
10336 KB |
Output is correct |
10 |
Correct |
17 ms |
10348 KB |
Output is correct |
11 |
Correct |
15 ms |
10404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9676 KB |
Output is correct |
2 |
Correct |
9 ms |
9676 KB |
Output is correct |
3 |
Correct |
7 ms |
9696 KB |
Output is correct |
4 |
Correct |
9 ms |
9696 KB |
Output is correct |
5 |
Correct |
11 ms |
9676 KB |
Output is correct |
6 |
Correct |
9 ms |
9676 KB |
Output is correct |
7 |
Correct |
7 ms |
9676 KB |
Output is correct |
8 |
Correct |
10 ms |
9668 KB |
Output is correct |
9 |
Correct |
8 ms |
9668 KB |
Output is correct |
10 |
Correct |
8 ms |
9660 KB |
Output is correct |
11 |
Correct |
9 ms |
9700 KB |
Output is correct |
12 |
Correct |
10 ms |
9712 KB |
Output is correct |
13 |
Correct |
9 ms |
9624 KB |
Output is correct |
14 |
Correct |
8 ms |
9696 KB |
Output is correct |
15 |
Correct |
10 ms |
9676 KB |
Output is correct |
16 |
Correct |
7 ms |
9676 KB |
Output is correct |
17 |
Correct |
9 ms |
9696 KB |
Output is correct |
18 |
Correct |
7 ms |
9676 KB |
Output is correct |
19 |
Correct |
11 ms |
9588 KB |
Output is correct |
20 |
Correct |
9 ms |
9676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
210 ms |
10912 KB |
Output is correct |
2 |
Correct |
328 ms |
10720 KB |
Output is correct |
3 |
Correct |
488 ms |
10920 KB |
Output is correct |
4 |
Correct |
16 ms |
10732 KB |
Output is correct |
5 |
Correct |
21 ms |
10736 KB |
Output is correct |
6 |
Correct |
18 ms |
10820 KB |
Output is correct |
7 |
Correct |
18 ms |
10828 KB |
Output is correct |
8 |
Correct |
17 ms |
10764 KB |
Output is correct |
9 |
Correct |
17 ms |
10700 KB |
Output is correct |
10 |
Correct |
19 ms |
10724 KB |
Output is correct |
11 |
Correct |
25 ms |
10732 KB |
Output is correct |
12 |
Correct |
18 ms |
10760 KB |
Output is correct |
13 |
Correct |
24 ms |
10688 KB |
Output is correct |
14 |
Correct |
21 ms |
10828 KB |
Output is correct |
15 |
Correct |
18 ms |
10784 KB |
Output is correct |
16 |
Correct |
16 ms |
10732 KB |
Output is correct |
17 |
Correct |
19 ms |
10812 KB |
Output is correct |
18 |
Correct |
620 ms |
10524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
10572 KB |
Output is correct |
2 |
Correct |
19 ms |
10680 KB |
Output is correct |
3 |
Correct |
19 ms |
10860 KB |
Output is correct |
4 |
Correct |
19 ms |
10844 KB |
Output is correct |
5 |
Correct |
22 ms |
10836 KB |
Output is correct |
6 |
Correct |
17 ms |
10708 KB |
Output is correct |
7 |
Correct |
20 ms |
10700 KB |
Output is correct |
8 |
Correct |
16 ms |
10816 KB |
Output is correct |
9 |
Correct |
20 ms |
10736 KB |
Output is correct |
10 |
Correct |
18 ms |
10764 KB |
Output is correct |
11 |
Correct |
20 ms |
10784 KB |
Output is correct |
12 |
Correct |
21 ms |
10760 KB |
Output is correct |
13 |
Correct |
27 ms |
10844 KB |
Output is correct |
14 |
Correct |
22 ms |
10716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
10728 KB |
Output is correct |
2 |
Correct |
19 ms |
10696 KB |
Output is correct |
3 |
Correct |
23 ms |
10744 KB |
Output is correct |
4 |
Correct |
22 ms |
10668 KB |
Output is correct |
5 |
Correct |
8 ms |
9648 KB |
Output is correct |
6 |
Correct |
13 ms |
10316 KB |
Output is correct |
7 |
Correct |
17 ms |
10352 KB |
Output is correct |
8 |
Correct |
16 ms |
10444 KB |
Output is correct |
9 |
Correct |
16 ms |
10336 KB |
Output is correct |
10 |
Correct |
12 ms |
9804 KB |
Output is correct |
11 |
Correct |
14 ms |
10324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
10448 KB |
Output is correct |
2 |
Correct |
18 ms |
10336 KB |
Output is correct |
3 |
Correct |
18 ms |
10408 KB |
Output is correct |
4 |
Correct |
15 ms |
10432 KB |
Output is correct |
5 |
Correct |
14 ms |
10436 KB |
Output is correct |
6 |
Correct |
14 ms |
10424 KB |
Output is correct |
7 |
Correct |
16 ms |
10444 KB |
Output is correct |
8 |
Correct |
14 ms |
10332 KB |
Output is correct |
9 |
Correct |
13 ms |
10336 KB |
Output is correct |
10 |
Correct |
17 ms |
10348 KB |
Output is correct |
11 |
Correct |
15 ms |
10404 KB |
Output is correct |
12 |
Correct |
9 ms |
9676 KB |
Output is correct |
13 |
Correct |
9 ms |
9676 KB |
Output is correct |
14 |
Correct |
7 ms |
9696 KB |
Output is correct |
15 |
Correct |
9 ms |
9696 KB |
Output is correct |
16 |
Correct |
11 ms |
9676 KB |
Output is correct |
17 |
Correct |
9 ms |
9676 KB |
Output is correct |
18 |
Correct |
7 ms |
9676 KB |
Output is correct |
19 |
Correct |
10 ms |
9668 KB |
Output is correct |
20 |
Correct |
8 ms |
9668 KB |
Output is correct |
21 |
Correct |
8 ms |
9660 KB |
Output is correct |
22 |
Correct |
9 ms |
9700 KB |
Output is correct |
23 |
Correct |
10 ms |
9712 KB |
Output is correct |
24 |
Correct |
9 ms |
9624 KB |
Output is correct |
25 |
Correct |
8 ms |
9696 KB |
Output is correct |
26 |
Correct |
10 ms |
9676 KB |
Output is correct |
27 |
Correct |
7 ms |
9676 KB |
Output is correct |
28 |
Correct |
9 ms |
9696 KB |
Output is correct |
29 |
Correct |
7 ms |
9676 KB |
Output is correct |
30 |
Correct |
11 ms |
9588 KB |
Output is correct |
31 |
Correct |
9 ms |
9676 KB |
Output is correct |
32 |
Correct |
210 ms |
10912 KB |
Output is correct |
33 |
Correct |
328 ms |
10720 KB |
Output is correct |
34 |
Correct |
488 ms |
10920 KB |
Output is correct |
35 |
Correct |
16 ms |
10732 KB |
Output is correct |
36 |
Correct |
21 ms |
10736 KB |
Output is correct |
37 |
Correct |
18 ms |
10820 KB |
Output is correct |
38 |
Correct |
18 ms |
10828 KB |
Output is correct |
39 |
Correct |
17 ms |
10764 KB |
Output is correct |
40 |
Correct |
17 ms |
10700 KB |
Output is correct |
41 |
Correct |
19 ms |
10724 KB |
Output is correct |
42 |
Correct |
25 ms |
10732 KB |
Output is correct |
43 |
Correct |
18 ms |
10760 KB |
Output is correct |
44 |
Correct |
24 ms |
10688 KB |
Output is correct |
45 |
Correct |
21 ms |
10828 KB |
Output is correct |
46 |
Correct |
18 ms |
10784 KB |
Output is correct |
47 |
Correct |
16 ms |
10732 KB |
Output is correct |
48 |
Correct |
19 ms |
10812 KB |
Output is correct |
49 |
Correct |
620 ms |
10524 KB |
Output is correct |
50 |
Correct |
15 ms |
10572 KB |
Output is correct |
51 |
Correct |
19 ms |
10680 KB |
Output is correct |
52 |
Correct |
19 ms |
10860 KB |
Output is correct |
53 |
Correct |
19 ms |
10844 KB |
Output is correct |
54 |
Correct |
22 ms |
10836 KB |
Output is correct |
55 |
Correct |
17 ms |
10708 KB |
Output is correct |
56 |
Correct |
20 ms |
10700 KB |
Output is correct |
57 |
Correct |
16 ms |
10816 KB |
Output is correct |
58 |
Correct |
20 ms |
10736 KB |
Output is correct |
59 |
Correct |
18 ms |
10764 KB |
Output is correct |
60 |
Correct |
20 ms |
10784 KB |
Output is correct |
61 |
Correct |
21 ms |
10760 KB |
Output is correct |
62 |
Correct |
27 ms |
10844 KB |
Output is correct |
63 |
Correct |
22 ms |
10716 KB |
Output is correct |
64 |
Correct |
22 ms |
10728 KB |
Output is correct |
65 |
Correct |
19 ms |
10696 KB |
Output is correct |
66 |
Correct |
23 ms |
10744 KB |
Output is correct |
67 |
Correct |
22 ms |
10668 KB |
Output is correct |
68 |
Correct |
8 ms |
9648 KB |
Output is correct |
69 |
Correct |
13 ms |
10316 KB |
Output is correct |
70 |
Correct |
17 ms |
10352 KB |
Output is correct |
71 |
Correct |
16 ms |
10444 KB |
Output is correct |
72 |
Correct |
16 ms |
10336 KB |
Output is correct |
73 |
Correct |
12 ms |
9804 KB |
Output is correct |
74 |
Correct |
14 ms |
10324 KB |
Output is correct |
75 |
Correct |
253 ms |
10884 KB |
Output is correct |
76 |
Correct |
366 ms |
10928 KB |
Output is correct |
77 |
Correct |
537 ms |
10928 KB |
Output is correct |
78 |
Correct |
558 ms |
10948 KB |
Output is correct |
79 |
Correct |
557 ms |
10928 KB |
Output is correct |
80 |
Correct |
18 ms |
10820 KB |
Output is correct |
81 |
Correct |
22 ms |
10880 KB |
Output is correct |
82 |
Correct |
21 ms |
10736 KB |
Output is correct |
83 |
Correct |
21 ms |
10792 KB |
Output is correct |
84 |
Correct |
17 ms |
10732 KB |
Output is correct |
85 |
Correct |
20 ms |
10820 KB |
Output is correct |
86 |
Correct |
22 ms |
10848 KB |
Output is correct |
87 |
Correct |
18 ms |
10740 KB |
Output is correct |
88 |
Correct |
26 ms |
10808 KB |
Output is correct |
89 |
Correct |
18 ms |
10736 KB |
Output is correct |
90 |
Correct |
30 ms |
10840 KB |
Output is correct |
91 |
Correct |
25 ms |
10760 KB |
Output is correct |
92 |
Correct |
44 ms |
10884 KB |
Output is correct |
93 |
Correct |
47 ms |
10844 KB |
Output is correct |
94 |
Correct |
38 ms |
10892 KB |
Output is correct |
95 |
Correct |
40 ms |
10828 KB |
Output is correct |
96 |
Correct |
126 ms |
10784 KB |
Output is correct |
97 |
Correct |
538 ms |
10888 KB |
Output is correct |
98 |
Correct |
747 ms |
10860 KB |
Output is correct |
99 |
Correct |
767 ms |
10844 KB |
Output is correct |
100 |
Correct |
689 ms |
10480 KB |
Output is correct |