#include <bits/stdc++.h>
using namespace std;
const int MX = 5042;
int n;
int deg[MX];
int baseDeg[MX];
int nxt[2 * MX];
bool vis[MX];
bool vis2[MX];
bool isOk[MX];
bool isAlice[MX];
bool isCharge[MX];
vector<int> rgraph[MX];
bool BFS() {
int start = 0;
int end = 0;
for (int i = 0; i < n; i++)
deg[i] = baseDeg[i];
for (int i = 0; i < n; i++) {
if (isCharge[i] && isOk[i])
nxt[end++] = i;
vis[i] = vis2[i] = false;
}
//cout << layer << ' ' << (int)nxt.size() << '\n';
while (start < end) {
auto cur = nxt[start++];
//cout << "cur is " << cur << '\n';
if (vis[cur])
continue;
vis[cur] = true;
for (auto& x: rgraph[cur]) {
if (!vis2[x] && ((--deg[x] == 0) || isAlice[x])) {
vis2[x] = true;
nxt[end++] = x;
}
}
}
for (int i = 0; i < n; i++) {
if (isOk[i] && !vis2[i]) {
isOk[i] = false;
return true;
}
}
return false;
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
n = (int)a.size();
for (int i = 0; i < (int)u.size(); i++) {
rgraph[v[i]].push_back(u[i]);
baseDeg[u[i]]++;
}
for (int i = 0; i < n; i++) {
isAlice[i] = a[i];
isCharge[i] = r[i];
isOk[i] = true;
}
while (BFS());
vector<int> ans (n);
for (int i = 0; i < n; i++)
ans[i] = isOk[i];
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
225 ms |
844 KB |
Output is correct |
2 |
Correct |
252 ms |
852 KB |
Output is correct |
3 |
Correct |
233 ms |
852 KB |
Output is correct |
4 |
Correct |
253 ms |
832 KB |
Output is correct |
5 |
Correct |
228 ms |
848 KB |
Output is correct |
6 |
Correct |
242 ms |
844 KB |
Output is correct |
7 |
Correct |
274 ms |
820 KB |
Output is correct |
8 |
Correct |
64 ms |
852 KB |
Output is correct |
9 |
Correct |
211 ms |
812 KB |
Output is correct |
10 |
Correct |
195 ms |
784 KB |
Output is correct |
11 |
Correct |
138 ms |
796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
173 ms |
1116 KB |
Output is correct |
2 |
Correct |
279 ms |
1116 KB |
Output is correct |
3 |
Correct |
344 ms |
1112 KB |
Output is correct |
4 |
Correct |
10 ms |
1108 KB |
Output is correct |
5 |
Correct |
174 ms |
1092 KB |
Output is correct |
6 |
Correct |
218 ms |
1088 KB |
Output is correct |
7 |
Correct |
8 ms |
1108 KB |
Output is correct |
8 |
Correct |
181 ms |
1108 KB |
Output is correct |
9 |
Correct |
36 ms |
1052 KB |
Output is correct |
10 |
Correct |
138 ms |
1056 KB |
Output is correct |
11 |
Correct |
167 ms |
1036 KB |
Output is correct |
12 |
Correct |
51 ms |
1004 KB |
Output is correct |
13 |
Correct |
6 ms |
1108 KB |
Output is correct |
14 |
Correct |
6 ms |
1136 KB |
Output is correct |
15 |
Correct |
6 ms |
1108 KB |
Output is correct |
16 |
Correct |
6 ms |
1084 KB |
Output is correct |
17 |
Correct |
6 ms |
1108 KB |
Output is correct |
18 |
Correct |
321 ms |
888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
980 KB |
Output is correct |
2 |
Correct |
209 ms |
1012 KB |
Output is correct |
3 |
Correct |
160 ms |
1048 KB |
Output is correct |
4 |
Correct |
338 ms |
1088 KB |
Output is correct |
5 |
Correct |
328 ms |
1092 KB |
Output is correct |
6 |
Correct |
247 ms |
1072 KB |
Output is correct |
7 |
Correct |
283 ms |
1064 KB |
Output is correct |
8 |
Correct |
207 ms |
1040 KB |
Output is correct |
9 |
Correct |
198 ms |
1044 KB |
Output is correct |
10 |
Correct |
6 ms |
1108 KB |
Output is correct |
11 |
Correct |
6 ms |
1108 KB |
Output is correct |
12 |
Correct |
6 ms |
1108 KB |
Output is correct |
13 |
Correct |
294 ms |
1076 KB |
Output is correct |
14 |
Correct |
235 ms |
1044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
340 ms |
1080 KB |
Output is correct |
2 |
Correct |
6 ms |
1108 KB |
Output is correct |
3 |
Correct |
228 ms |
1108 KB |
Output is correct |
4 |
Correct |
6 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
40 ms |
764 KB |
Output is correct |
7 |
Correct |
18 ms |
852 KB |
Output is correct |
8 |
Correct |
21 ms |
832 KB |
Output is correct |
9 |
Correct |
23 ms |
940 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
9 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
225 ms |
844 KB |
Output is correct |
2 |
Correct |
252 ms |
852 KB |
Output is correct |
3 |
Correct |
233 ms |
852 KB |
Output is correct |
4 |
Correct |
253 ms |
832 KB |
Output is correct |
5 |
Correct |
228 ms |
848 KB |
Output is correct |
6 |
Correct |
242 ms |
844 KB |
Output is correct |
7 |
Correct |
274 ms |
820 KB |
Output is correct |
8 |
Correct |
64 ms |
852 KB |
Output is correct |
9 |
Correct |
211 ms |
812 KB |
Output is correct |
10 |
Correct |
195 ms |
784 KB |
Output is correct |
11 |
Correct |
138 ms |
796 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
173 ms |
1116 KB |
Output is correct |
33 |
Correct |
279 ms |
1116 KB |
Output is correct |
34 |
Correct |
344 ms |
1112 KB |
Output is correct |
35 |
Correct |
10 ms |
1108 KB |
Output is correct |
36 |
Correct |
174 ms |
1092 KB |
Output is correct |
37 |
Correct |
218 ms |
1088 KB |
Output is correct |
38 |
Correct |
8 ms |
1108 KB |
Output is correct |
39 |
Correct |
181 ms |
1108 KB |
Output is correct |
40 |
Correct |
36 ms |
1052 KB |
Output is correct |
41 |
Correct |
138 ms |
1056 KB |
Output is correct |
42 |
Correct |
167 ms |
1036 KB |
Output is correct |
43 |
Correct |
51 ms |
1004 KB |
Output is correct |
44 |
Correct |
6 ms |
1108 KB |
Output is correct |
45 |
Correct |
6 ms |
1136 KB |
Output is correct |
46 |
Correct |
6 ms |
1108 KB |
Output is correct |
47 |
Correct |
6 ms |
1084 KB |
Output is correct |
48 |
Correct |
6 ms |
1108 KB |
Output is correct |
49 |
Correct |
321 ms |
888 KB |
Output is correct |
50 |
Correct |
5 ms |
980 KB |
Output is correct |
51 |
Correct |
209 ms |
1012 KB |
Output is correct |
52 |
Correct |
160 ms |
1048 KB |
Output is correct |
53 |
Correct |
338 ms |
1088 KB |
Output is correct |
54 |
Correct |
328 ms |
1092 KB |
Output is correct |
55 |
Correct |
247 ms |
1072 KB |
Output is correct |
56 |
Correct |
283 ms |
1064 KB |
Output is correct |
57 |
Correct |
207 ms |
1040 KB |
Output is correct |
58 |
Correct |
198 ms |
1044 KB |
Output is correct |
59 |
Correct |
6 ms |
1108 KB |
Output is correct |
60 |
Correct |
6 ms |
1108 KB |
Output is correct |
61 |
Correct |
6 ms |
1108 KB |
Output is correct |
62 |
Correct |
294 ms |
1076 KB |
Output is correct |
63 |
Correct |
235 ms |
1044 KB |
Output is correct |
64 |
Correct |
340 ms |
1080 KB |
Output is correct |
65 |
Correct |
6 ms |
1108 KB |
Output is correct |
66 |
Correct |
228 ms |
1108 KB |
Output is correct |
67 |
Correct |
6 ms |
980 KB |
Output is correct |
68 |
Correct |
1 ms |
468 KB |
Output is correct |
69 |
Correct |
40 ms |
764 KB |
Output is correct |
70 |
Correct |
18 ms |
852 KB |
Output is correct |
71 |
Correct |
21 ms |
832 KB |
Output is correct |
72 |
Correct |
23 ms |
940 KB |
Output is correct |
73 |
Correct |
2 ms |
596 KB |
Output is correct |
74 |
Correct |
9 ms |
852 KB |
Output is correct |
75 |
Correct |
115 ms |
1116 KB |
Output is correct |
76 |
Correct |
378 ms |
1120 KB |
Output is correct |
77 |
Correct |
435 ms |
1108 KB |
Output is correct |
78 |
Correct |
465 ms |
1116 KB |
Output is correct |
79 |
Correct |
456 ms |
1112 KB |
Output is correct |
80 |
Correct |
7 ms |
1108 KB |
Output is correct |
81 |
Correct |
347 ms |
1092 KB |
Output is correct |
82 |
Correct |
367 ms |
1084 KB |
Output is correct |
83 |
Correct |
207 ms |
1092 KB |
Output is correct |
84 |
Correct |
278 ms |
1100 KB |
Output is correct |
85 |
Correct |
371 ms |
1076 KB |
Output is correct |
86 |
Correct |
303 ms |
1088 KB |
Output is correct |
87 |
Correct |
274 ms |
1068 KB |
Output is correct |
88 |
Correct |
625 ms |
1092 KB |
Output is correct |
89 |
Correct |
350 ms |
1072 KB |
Output is correct |
90 |
Correct |
572 ms |
1096 KB |
Output is correct |
91 |
Correct |
471 ms |
1088 KB |
Output is correct |
92 |
Correct |
477 ms |
1124 KB |
Output is correct |
93 |
Correct |
559 ms |
1084 KB |
Output is correct |
94 |
Correct |
663 ms |
1112 KB |
Output is correct |
95 |
Correct |
567 ms |
1108 KB |
Output is correct |
96 |
Correct |
264 ms |
1032 KB |
Output is correct |
97 |
Correct |
533 ms |
1108 KB |
Output is correct |
98 |
Correct |
702 ms |
1080 KB |
Output is correct |
99 |
Correct |
629 ms |
1072 KB |
Output is correct |
100 |
Correct |
323 ms |
920 KB |
Output is correct |