#include "bulb.h"
#include <vector>
using namespace std;
vector<int> L, R;
int n;
bool vis[300001];
bool chB[300001];
bool res[300001];
bool inZ[300001];
void dfs(int x) {
if (vis[x]) return;
vis[x] = 1;
if (L[x] < 0) {
res[x] = L[x] == -2;
}
else {
dfs(L[x]);
res[x] = res[L[x]];
}
if (R[x] < 0) {
chB[x] = R[x] == -2;
}
else {
dfs(R[x]);
chB[x] = res[R[x]];
}
}
int FindWinner(int T, vector<int> _L, vector<int> _R) {
n = _L.size();
L = _L;
R = _R;
for (int x = 0; x < n; ++x) {
swap(L[x], R[x]);
int i;
for (i = 0; i < n; ++i) {
vis[i] = 0;
inZ[i] = 0;
}
for (int i = 0; i >= 0; i = L[i]) inZ[i] = 1;
dfs(0);
for (i = 0; i < n; ++i) {
if (inZ[i]) {
if (chB[i]) break;
}
else {
if (res[0]) break;
}
}
if (i == n) return 1;
swap(L[x], R[x]);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
11 ms |
400 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
11 ms |
404 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
11 ms |
428 KB |
Output is correct |
10 |
Correct |
11 ms |
428 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
11 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
11 ms |
400 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
11 ms |
404 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
11 ms |
428 KB |
Output is correct |
12 |
Correct |
11 ms |
428 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
11 ms |
396 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
4 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
392 KB |
Output is correct |
20 |
Correct |
11 ms |
364 KB |
Output is correct |
21 |
Correct |
11 ms |
376 KB |
Output is correct |
22 |
Correct |
8 ms |
376 KB |
Output is correct |
23 |
Correct |
11 ms |
396 KB |
Output is correct |
24 |
Correct |
11 ms |
392 KB |
Output is correct |
25 |
Correct |
8 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
11 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
11 ms |
400 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
11 ms |
404 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
11 ms |
428 KB |
Output is correct |
12 |
Correct |
11 ms |
428 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
11 ms |
396 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
4 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
392 KB |
Output is correct |
20 |
Correct |
11 ms |
364 KB |
Output is correct |
21 |
Correct |
11 ms |
376 KB |
Output is correct |
22 |
Correct |
8 ms |
376 KB |
Output is correct |
23 |
Correct |
11 ms |
396 KB |
Output is correct |
24 |
Correct |
11 ms |
392 KB |
Output is correct |
25 |
Correct |
8 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
348 KB |
Output is correct |
27 |
Execution timed out |
1004 ms |
10512 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |