#include "bulb.h"
using namespace std;
int d[300003];
int c[300003];
void dfs1(int x, vector<int> &L) {
d[x] = L[x];
if (d[x] >= 0) {
dfs1(d[x], L);
d[x] = d[d[x]];
}
}
void dfs2(int x, vector<int> &L, vector<int> &R) {
if (L[x] >= 0) dfs2(L[x], L, R);
if (R[x] >= 0) dfs2(R[x], L, R);
c[x] = R[x] == -2 || d[R[x]] == -2 || (L[x] >= 0 && c[L[x]] == -2) ? -2 : -1;
}
int FindWinner(int T, std::vector<int> L, std::vector<int> R){
int i, N = L.size();
for (i = 0; i < N; i++) if (!d[i]) dfs1(i, L);
if (d[0] == -2) return 0;
dfs2(0, L, R);
for (i = 0; i >= 0; i = L[i]) {
if (R[i] < 0 || c[R[i]] == -1) return 1;
if (R[i] == -2 || d[R[i]] == -2) return 0;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |