#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(r[nod] == -1) 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();
if(N == 1)
{
if(L[0] == -1) return 1;
return 0;
}
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 |
292 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
420 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
292 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
420 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
284 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
316 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
292 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
420 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
284 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
316 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
91 ms |
10812 KB |
Output is correct |
28 |
Correct |
91 ms |
10912 KB |
Output is correct |
29 |
Correct |
91 ms |
10936 KB |
Output is correct |
30 |
Correct |
97 ms |
20344 KB |
Output is correct |
31 |
Correct |
96 ms |
20316 KB |
Output is correct |
32 |
Correct |
90 ms |
10844 KB |
Output is correct |
33 |
Correct |
90 ms |
11032 KB |
Output is correct |
34 |
Correct |
90 ms |
10908 KB |
Output is correct |
35 |
Correct |
89 ms |
10872 KB |
Output is correct |
36 |
Correct |
89 ms |
10912 KB |
Output is correct |
37 |
Correct |
89 ms |
10824 KB |
Output is correct |
38 |
Correct |
107 ms |
10872 KB |
Output is correct |
39 |
Correct |
92 ms |
10916 KB |
Output is correct |
40 |
Correct |
90 ms |
10932 KB |
Output is correct |
41 |
Correct |
92 ms |
10912 KB |
Output is correct |
42 |
Correct |
91 ms |
10916 KB |
Output is correct |
43 |
Correct |
91 ms |
10912 KB |
Output is correct |
44 |
Correct |
90 ms |
10936 KB |
Output is correct |
45 |
Correct |
89 ms |
10844 KB |
Output is correct |
46 |
Correct |
90 ms |
10936 KB |
Output is correct |
47 |
Correct |
92 ms |
13024 KB |
Output is correct |
48 |
Correct |
93 ms |
13000 KB |
Output is correct |
49 |
Correct |
91 ms |
12960 KB |
Output is correct |
50 |
Correct |
91 ms |
13032 KB |
Output is correct |