#include <bits/stdc++.h>
#include "bulb.h"
using namespace std;
int N;
vector<int> l, r, whr, good, down;
void DFS(int nod)
{
if(nod < 0) return;
DFS(l[nod]);
DFS(r[nod]);
if(l[nod] < 0) whr[nod] = l[nod];
else whr[nod] = whr[ l[nod] ];
good[nod] = (whr[nod] == -1);
if(r[nod] < 0) good[nod] &= (r[nod] == -1);
else good[nod] &= (whr[ r[nod] ] == -1);
if(l[nod] < 0) down[nod] = good[nod];
else down[nod] = good[nod] & down[ l[nod] ];
}
int DFS2(int nod)
{
if(r[nod] > 0 && down[ r[nod] ]) return 1;
if(l[nod] < 0)
{
if(good[nod]) return 1;
return 0;
}
if(good[nod]) return DFS2(l[nod]);
return 0;
}
int FindWinner(int T, std::vector<int> L, std::vector<int> R)
{
N = L.size();
l = L, r = R;
whr.resize(N); good.resize(N); down.resize(N);
DFS(0);
if(whr[0] == -2) return 0;
int ans = DFS2(0);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 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 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |