#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
10316 KB |
Output is correct |
2 |
Correct |
13 ms |
10316 KB |
Output is correct |
3 |
Correct |
17 ms |
10316 KB |
Output is correct |
4 |
Correct |
17 ms |
10324 KB |
Output is correct |
5 |
Correct |
16 ms |
10292 KB |
Output is correct |
6 |
Correct |
14 ms |
10316 KB |
Output is correct |
7 |
Correct |
12 ms |
10316 KB |
Output is correct |
8 |
Correct |
15 ms |
10272 KB |
Output is correct |
9 |
Correct |
15 ms |
10316 KB |
Output is correct |
10 |
Correct |
16 ms |
10296 KB |
Output is correct |
11 |
Correct |
11 ms |
10316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9676 KB |
Output is correct |
2 |
Correct |
10 ms |
9676 KB |
Output is correct |
3 |
Correct |
7 ms |
9676 KB |
Output is correct |
4 |
Correct |
8 ms |
9656 KB |
Output is correct |
5 |
Correct |
7 ms |
9676 KB |
Output is correct |
6 |
Correct |
7 ms |
9676 KB |
Output is correct |
7 |
Correct |
8 ms |
9676 KB |
Output is correct |
8 |
Correct |
9 ms |
9676 KB |
Output is correct |
9 |
Correct |
9 ms |
9676 KB |
Output is correct |
10 |
Correct |
8 ms |
9676 KB |
Output is correct |
11 |
Correct |
8 ms |
9676 KB |
Output is correct |
12 |
Correct |
8 ms |
9700 KB |
Output is correct |
13 |
Correct |
8 ms |
9676 KB |
Output is correct |
14 |
Correct |
8 ms |
9676 KB |
Output is correct |
15 |
Correct |
8 ms |
9676 KB |
Output is correct |
16 |
Correct |
9 ms |
9600 KB |
Output is correct |
17 |
Correct |
8 ms |
9676 KB |
Output is correct |
18 |
Correct |
9 ms |
9676 KB |
Output is correct |
19 |
Correct |
8 ms |
9676 KB |
Output is correct |
20 |
Correct |
8 ms |
9676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
189 ms |
10700 KB |
Output is correct |
2 |
Correct |
350 ms |
10716 KB |
Output is correct |
3 |
Correct |
520 ms |
10716 KB |
Output is correct |
4 |
Correct |
16 ms |
10620 KB |
Output is correct |
5 |
Correct |
19 ms |
10532 KB |
Output is correct |
6 |
Correct |
23 ms |
10572 KB |
Output is correct |
7 |
Correct |
18 ms |
10532 KB |
Output is correct |
8 |
Correct |
21 ms |
10532 KB |
Output is correct |
9 |
Correct |
14 ms |
10528 KB |
Output is correct |
10 |
Correct |
15 ms |
10572 KB |
Output is correct |
11 |
Correct |
22 ms |
10564 KB |
Output is correct |
12 |
Correct |
17 ms |
10516 KB |
Output is correct |
13 |
Correct |
15 ms |
10528 KB |
Output is correct |
14 |
Correct |
16 ms |
10572 KB |
Output is correct |
15 |
Correct |
15 ms |
10620 KB |
Output is correct |
16 |
Correct |
16 ms |
10560 KB |
Output is correct |
17 |
Correct |
16 ms |
10528 KB |
Output is correct |
18 |
Correct |
593 ms |
10416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
10444 KB |
Output is correct |
2 |
Correct |
14 ms |
10444 KB |
Output is correct |
3 |
Correct |
18 ms |
10640 KB |
Output is correct |
4 |
Correct |
21 ms |
10544 KB |
Output is correct |
5 |
Correct |
16 ms |
10572 KB |
Output is correct |
6 |
Correct |
19 ms |
10624 KB |
Output is correct |
7 |
Correct |
19 ms |
10520 KB |
Output is correct |
8 |
Correct |
20 ms |
10520 KB |
Output is correct |
9 |
Correct |
19 ms |
10508 KB |
Output is correct |
10 |
Correct |
20 ms |
10572 KB |
Output is correct |
11 |
Correct |
20 ms |
10656 KB |
Output is correct |
12 |
Correct |
21 ms |
10528 KB |
Output is correct |
13 |
Correct |
24 ms |
10656 KB |
Output is correct |
14 |
Correct |
15 ms |
10528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
10532 KB |
Output is correct |
2 |
Correct |
21 ms |
10572 KB |
Output is correct |
3 |
Correct |
24 ms |
10540 KB |
Output is correct |
4 |
Correct |
19 ms |
10520 KB |
Output is correct |
5 |
Correct |
9 ms |
9676 KB |
Output is correct |
6 |
Correct |
14 ms |
10284 KB |
Output is correct |
7 |
Correct |
15 ms |
10188 KB |
Output is correct |
8 |
Correct |
14 ms |
10188 KB |
Output is correct |
9 |
Correct |
15 ms |
10316 KB |
Output is correct |
10 |
Correct |
8 ms |
9876 KB |
Output is correct |
11 |
Correct |
14 ms |
10200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
10316 KB |
Output is correct |
2 |
Correct |
13 ms |
10316 KB |
Output is correct |
3 |
Correct |
17 ms |
10316 KB |
Output is correct |
4 |
Correct |
17 ms |
10324 KB |
Output is correct |
5 |
Correct |
16 ms |
10292 KB |
Output is correct |
6 |
Correct |
14 ms |
10316 KB |
Output is correct |
7 |
Correct |
12 ms |
10316 KB |
Output is correct |
8 |
Correct |
15 ms |
10272 KB |
Output is correct |
9 |
Correct |
15 ms |
10316 KB |
Output is correct |
10 |
Correct |
16 ms |
10296 KB |
Output is correct |
11 |
Correct |
11 ms |
10316 KB |
Output is correct |
12 |
Correct |
8 ms |
9676 KB |
Output is correct |
13 |
Correct |
10 ms |
9676 KB |
Output is correct |
14 |
Correct |
7 ms |
9676 KB |
Output is correct |
15 |
Correct |
8 ms |
9656 KB |
Output is correct |
16 |
Correct |
7 ms |
9676 KB |
Output is correct |
17 |
Correct |
7 ms |
9676 KB |
Output is correct |
18 |
Correct |
8 ms |
9676 KB |
Output is correct |
19 |
Correct |
9 ms |
9676 KB |
Output is correct |
20 |
Correct |
9 ms |
9676 KB |
Output is correct |
21 |
Correct |
8 ms |
9676 KB |
Output is correct |
22 |
Correct |
8 ms |
9676 KB |
Output is correct |
23 |
Correct |
8 ms |
9700 KB |
Output is correct |
24 |
Correct |
8 ms |
9676 KB |
Output is correct |
25 |
Correct |
8 ms |
9676 KB |
Output is correct |
26 |
Correct |
8 ms |
9676 KB |
Output is correct |
27 |
Correct |
9 ms |
9600 KB |
Output is correct |
28 |
Correct |
8 ms |
9676 KB |
Output is correct |
29 |
Correct |
9 ms |
9676 KB |
Output is correct |
30 |
Correct |
8 ms |
9676 KB |
Output is correct |
31 |
Correct |
8 ms |
9676 KB |
Output is correct |
32 |
Correct |
189 ms |
10700 KB |
Output is correct |
33 |
Correct |
350 ms |
10716 KB |
Output is correct |
34 |
Correct |
520 ms |
10716 KB |
Output is correct |
35 |
Correct |
16 ms |
10620 KB |
Output is correct |
36 |
Correct |
19 ms |
10532 KB |
Output is correct |
37 |
Correct |
23 ms |
10572 KB |
Output is correct |
38 |
Correct |
18 ms |
10532 KB |
Output is correct |
39 |
Correct |
21 ms |
10532 KB |
Output is correct |
40 |
Correct |
14 ms |
10528 KB |
Output is correct |
41 |
Correct |
15 ms |
10572 KB |
Output is correct |
42 |
Correct |
22 ms |
10564 KB |
Output is correct |
43 |
Correct |
17 ms |
10516 KB |
Output is correct |
44 |
Correct |
15 ms |
10528 KB |
Output is correct |
45 |
Correct |
16 ms |
10572 KB |
Output is correct |
46 |
Correct |
15 ms |
10620 KB |
Output is correct |
47 |
Correct |
16 ms |
10560 KB |
Output is correct |
48 |
Correct |
16 ms |
10528 KB |
Output is correct |
49 |
Correct |
593 ms |
10416 KB |
Output is correct |
50 |
Correct |
14 ms |
10444 KB |
Output is correct |
51 |
Correct |
14 ms |
10444 KB |
Output is correct |
52 |
Correct |
18 ms |
10640 KB |
Output is correct |
53 |
Correct |
21 ms |
10544 KB |
Output is correct |
54 |
Correct |
16 ms |
10572 KB |
Output is correct |
55 |
Correct |
19 ms |
10624 KB |
Output is correct |
56 |
Correct |
19 ms |
10520 KB |
Output is correct |
57 |
Correct |
20 ms |
10520 KB |
Output is correct |
58 |
Correct |
19 ms |
10508 KB |
Output is correct |
59 |
Correct |
20 ms |
10572 KB |
Output is correct |
60 |
Correct |
20 ms |
10656 KB |
Output is correct |
61 |
Correct |
21 ms |
10528 KB |
Output is correct |
62 |
Correct |
24 ms |
10656 KB |
Output is correct |
63 |
Correct |
15 ms |
10528 KB |
Output is correct |
64 |
Correct |
20 ms |
10532 KB |
Output is correct |
65 |
Correct |
21 ms |
10572 KB |
Output is correct |
66 |
Correct |
24 ms |
10540 KB |
Output is correct |
67 |
Correct |
19 ms |
10520 KB |
Output is correct |
68 |
Correct |
9 ms |
9676 KB |
Output is correct |
69 |
Correct |
14 ms |
10284 KB |
Output is correct |
70 |
Correct |
15 ms |
10188 KB |
Output is correct |
71 |
Correct |
14 ms |
10188 KB |
Output is correct |
72 |
Correct |
15 ms |
10316 KB |
Output is correct |
73 |
Correct |
8 ms |
9876 KB |
Output is correct |
74 |
Correct |
14 ms |
10200 KB |
Output is correct |
75 |
Correct |
249 ms |
10692 KB |
Output is correct |
76 |
Correct |
363 ms |
10820 KB |
Output is correct |
77 |
Correct |
520 ms |
10712 KB |
Output is correct |
78 |
Correct |
499 ms |
10720 KB |
Output is correct |
79 |
Correct |
508 ms |
10820 KB |
Output is correct |
80 |
Correct |
19 ms |
10572 KB |
Output is correct |
81 |
Correct |
22 ms |
10524 KB |
Output is correct |
82 |
Correct |
22 ms |
10536 KB |
Output is correct |
83 |
Correct |
25 ms |
10600 KB |
Output is correct |
84 |
Correct |
20 ms |
10648 KB |
Output is correct |
85 |
Correct |
21 ms |
10572 KB |
Output is correct |
86 |
Correct |
20 ms |
10648 KB |
Output is correct |
87 |
Correct |
18 ms |
10612 KB |
Output is correct |
88 |
Correct |
23 ms |
10628 KB |
Output is correct |
89 |
Correct |
21 ms |
10508 KB |
Output is correct |
90 |
Correct |
25 ms |
10668 KB |
Output is correct |
91 |
Correct |
31 ms |
10656 KB |
Output is correct |
92 |
Correct |
42 ms |
10652 KB |
Output is correct |
93 |
Correct |
47 ms |
10592 KB |
Output is correct |
94 |
Correct |
44 ms |
10652 KB |
Output is correct |
95 |
Correct |
40 ms |
10652 KB |
Output is correct |
96 |
Correct |
123 ms |
10620 KB |
Output is correct |
97 |
Correct |
531 ms |
10676 KB |
Output is correct |
98 |
Correct |
770 ms |
10788 KB |
Output is correct |
99 |
Correct |
799 ms |
10904 KB |
Output is correct |
100 |
Correct |
705 ms |
10524 KB |
Output is correct |