#include <bits/stdc++.h>
using namespace std;
const int MX = 5042;
int n;
int deg[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] = 0;
for (int i = 0; i < n; i++) {
for (auto& x: rgraph[i])
deg[x]++;
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]);
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 |
333 ms |
844 KB |
Output is correct |
2 |
Correct |
353 ms |
900 KB |
Output is correct |
3 |
Correct |
348 ms |
900 KB |
Output is correct |
4 |
Correct |
344 ms |
908 KB |
Output is correct |
5 |
Correct |
339 ms |
896 KB |
Output is correct |
6 |
Correct |
318 ms |
824 KB |
Output is correct |
7 |
Correct |
429 ms |
916 KB |
Output is correct |
8 |
Correct |
91 ms |
896 KB |
Output is correct |
9 |
Correct |
301 ms |
868 KB |
Output is correct |
10 |
Correct |
282 ms |
852 KB |
Output is correct |
11 |
Correct |
231 ms |
852 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 |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
340 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 |
1 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 |
0 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 |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
549 ms |
1104 KB |
Output is correct |
2 |
Correct |
652 ms |
1300 KB |
Output is correct |
3 |
Correct |
688 ms |
1304 KB |
Output is correct |
4 |
Correct |
7 ms |
1236 KB |
Output is correct |
5 |
Correct |
295 ms |
1284 KB |
Output is correct |
6 |
Correct |
628 ms |
1276 KB |
Output is correct |
7 |
Correct |
7 ms |
1236 KB |
Output is correct |
8 |
Correct |
444 ms |
1272 KB |
Output is correct |
9 |
Correct |
412 ms |
1212 KB |
Output is correct |
10 |
Correct |
251 ms |
1240 KB |
Output is correct |
11 |
Correct |
362 ms |
1212 KB |
Output is correct |
12 |
Correct |
386 ms |
1184 KB |
Output is correct |
13 |
Correct |
6 ms |
1236 KB |
Output is correct |
14 |
Correct |
6 ms |
1340 KB |
Output is correct |
15 |
Correct |
6 ms |
1212 KB |
Output is correct |
16 |
Correct |
7 ms |
1236 KB |
Output is correct |
17 |
Correct |
7 ms |
1236 KB |
Output is correct |
18 |
Correct |
549 ms |
992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
980 KB |
Output is correct |
2 |
Correct |
318 ms |
1172 KB |
Output is correct |
3 |
Correct |
523 ms |
1268 KB |
Output is correct |
4 |
Correct |
714 ms |
1272 KB |
Output is correct |
5 |
Correct |
583 ms |
1264 KB |
Output is correct |
6 |
Correct |
364 ms |
1256 KB |
Output is correct |
7 |
Correct |
452 ms |
1244 KB |
Output is correct |
8 |
Correct |
555 ms |
1212 KB |
Output is correct |
9 |
Correct |
303 ms |
1204 KB |
Output is correct |
10 |
Correct |
7 ms |
1244 KB |
Output is correct |
11 |
Correct |
6 ms |
1244 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
478 ms |
1276 KB |
Output is correct |
14 |
Correct |
338 ms |
1236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
515 ms |
1060 KB |
Output is correct |
2 |
Correct |
7 ms |
1108 KB |
Output is correct |
3 |
Correct |
310 ms |
1072 KB |
Output is correct |
4 |
Correct |
6 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
252 ms |
756 KB |
Output is correct |
7 |
Correct |
22 ms |
852 KB |
Output is correct |
8 |
Correct |
46 ms |
852 KB |
Output is correct |
9 |
Correct |
31 ms |
852 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
12 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
333 ms |
844 KB |
Output is correct |
2 |
Correct |
353 ms |
900 KB |
Output is correct |
3 |
Correct |
348 ms |
900 KB |
Output is correct |
4 |
Correct |
344 ms |
908 KB |
Output is correct |
5 |
Correct |
339 ms |
896 KB |
Output is correct |
6 |
Correct |
318 ms |
824 KB |
Output is correct |
7 |
Correct |
429 ms |
916 KB |
Output is correct |
8 |
Correct |
91 ms |
896 KB |
Output is correct |
9 |
Correct |
301 ms |
868 KB |
Output is correct |
10 |
Correct |
282 ms |
852 KB |
Output is correct |
11 |
Correct |
231 ms |
852 KB |
Output is correct |
12 |
Correct |
0 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 |
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 |
1 ms |
340 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 |
1 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 |
0 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 |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
549 ms |
1104 KB |
Output is correct |
33 |
Correct |
652 ms |
1300 KB |
Output is correct |
34 |
Correct |
688 ms |
1304 KB |
Output is correct |
35 |
Correct |
7 ms |
1236 KB |
Output is correct |
36 |
Correct |
295 ms |
1284 KB |
Output is correct |
37 |
Correct |
628 ms |
1276 KB |
Output is correct |
38 |
Correct |
7 ms |
1236 KB |
Output is correct |
39 |
Correct |
444 ms |
1272 KB |
Output is correct |
40 |
Correct |
412 ms |
1212 KB |
Output is correct |
41 |
Correct |
251 ms |
1240 KB |
Output is correct |
42 |
Correct |
362 ms |
1212 KB |
Output is correct |
43 |
Correct |
386 ms |
1184 KB |
Output is correct |
44 |
Correct |
6 ms |
1236 KB |
Output is correct |
45 |
Correct |
6 ms |
1340 KB |
Output is correct |
46 |
Correct |
6 ms |
1212 KB |
Output is correct |
47 |
Correct |
7 ms |
1236 KB |
Output is correct |
48 |
Correct |
7 ms |
1236 KB |
Output is correct |
49 |
Correct |
549 ms |
992 KB |
Output is correct |
50 |
Correct |
6 ms |
980 KB |
Output is correct |
51 |
Correct |
318 ms |
1172 KB |
Output is correct |
52 |
Correct |
523 ms |
1268 KB |
Output is correct |
53 |
Correct |
714 ms |
1272 KB |
Output is correct |
54 |
Correct |
583 ms |
1264 KB |
Output is correct |
55 |
Correct |
364 ms |
1256 KB |
Output is correct |
56 |
Correct |
452 ms |
1244 KB |
Output is correct |
57 |
Correct |
555 ms |
1212 KB |
Output is correct |
58 |
Correct |
303 ms |
1204 KB |
Output is correct |
59 |
Correct |
7 ms |
1244 KB |
Output is correct |
60 |
Correct |
6 ms |
1244 KB |
Output is correct |
61 |
Correct |
7 ms |
1236 KB |
Output is correct |
62 |
Correct |
478 ms |
1276 KB |
Output is correct |
63 |
Correct |
338 ms |
1236 KB |
Output is correct |
64 |
Correct |
515 ms |
1060 KB |
Output is correct |
65 |
Correct |
7 ms |
1108 KB |
Output is correct |
66 |
Correct |
310 ms |
1072 KB |
Output is correct |
67 |
Correct |
6 ms |
980 KB |
Output is correct |
68 |
Correct |
1 ms |
468 KB |
Output is correct |
69 |
Correct |
252 ms |
756 KB |
Output is correct |
70 |
Correct |
22 ms |
852 KB |
Output is correct |
71 |
Correct |
46 ms |
852 KB |
Output is correct |
72 |
Correct |
31 ms |
852 KB |
Output is correct |
73 |
Correct |
2 ms |
596 KB |
Output is correct |
74 |
Correct |
12 ms |
852 KB |
Output is correct |
75 |
Correct |
361 ms |
1268 KB |
Output is correct |
76 |
Correct |
753 ms |
1312 KB |
Output is correct |
77 |
Correct |
802 ms |
1300 KB |
Output is correct |
78 |
Correct |
790 ms |
1304 KB |
Output is correct |
79 |
Correct |
782 ms |
1296 KB |
Output is correct |
80 |
Correct |
8 ms |
1236 KB |
Output is correct |
81 |
Correct |
631 ms |
1264 KB |
Output is correct |
82 |
Correct |
571 ms |
1268 KB |
Output is correct |
83 |
Correct |
337 ms |
1276 KB |
Output is correct |
84 |
Correct |
492 ms |
1308 KB |
Output is correct |
85 |
Correct |
766 ms |
1260 KB |
Output is correct |
86 |
Correct |
532 ms |
1272 KB |
Output is correct |
87 |
Correct |
694 ms |
1256 KB |
Output is correct |
88 |
Correct |
928 ms |
1284 KB |
Output is correct |
89 |
Correct |
611 ms |
1264 KB |
Output is correct |
90 |
Correct |
1010 ms |
1280 KB |
Output is correct |
91 |
Correct |
898 ms |
1292 KB |
Output is correct |
92 |
Correct |
761 ms |
1296 KB |
Output is correct |
93 |
Correct |
901 ms |
1280 KB |
Output is correct |
94 |
Correct |
953 ms |
1284 KB |
Output is correct |
95 |
Correct |
863 ms |
1280 KB |
Output is correct |
96 |
Correct |
385 ms |
1236 KB |
Output is correct |
97 |
Correct |
932 ms |
1244 KB |
Output is correct |
98 |
Correct |
1000 ms |
1260 KB |
Output is correct |
99 |
Correct |
986 ms |
1248 KB |
Output is correct |
100 |
Correct |
564 ms |
988 KB |
Output is correct |