#include "bulb.h"
#include <bits/stdc++.h>
using namespace std;
int wL[300005], wR[300005];
int TL[300005], TR[300005];
int l[300005], r[300005];
bool dfs(int nod, bool s){
if(nod == -1 && s == 1) return 1;
if(nod < 0) return 0;
if(s == 0){
bool ok1 = dfs(l[nod], 0);
bool ok2 = dfs(r[nod], 1);
return ok1 | ok2;
}
else{
if(wL[nod] == -2 || wR[nod] == -2) return 0;
if(nod == -2) return 0;
return dfs(l[nod], 1);
}
}
int FindWinner(int T, std::vector<int> L, std::vector<int> R){
int N = L.size();
for(int i = 0; i < N ; ++i) l[i] = L[i], r[i] = R[i];
for(int i = 0; i < N ; ++i) TL[i] = TR[i] = -1;
for(int i = 0; i < N ; ++i)
if(L[i] >= 0) TL[L[i]] = i;
for(int i = 0; i < N ; ++i)
if(R[i] >= 0) TR[R[i]] = i;
for(int i = 0; i < N ; ++i){
if(L[i] >= 0) continue ;
int nod = i;
while(nod >= 0){
wL[nod] = L[nod];
nod = TL[nod];
}
}
for(int i = 0; i < N ; ++i){
if(R[i] >= 0) continue ;
int nod = i;
while(nod >= 0){
wR[TR[nod]] = wL[nod];
nod = TR[nod];
}
}
if(wL[0] == -2) return 0;
bool check = dfs(0, 0);
if(!check) return 0;
if(wR[0] == -2){
bool check = dfs(R[0], 0);
if(!check) return 0;
}
int nod = 0, nr = 0;
while(nod >= 0){
if(wR[nod] == 0) ++nr;
nod = L[nod];
}
if(nr > 1) return 0;
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |