#include "bulb.h"
#include <bits/stdc++.h>
using namespace std;
int FindWinner(int T, std::vector<int> L, std::vector<int> R){
int n = L.size();
vector<vector<int>> way(n, vector<int>(2));
for(int i = 0; i < n; ++i){
way[i][0] = L[i];
way[i][1] = R[i];
}
vector<int> tchk(n), ocnt(n);
int mn = (int)1e9;
vector<int> diff;
auto dfs = [&](auto&&self, int x, int pre)->void{
if(x == -2){
mn = min(mn, (int)diff.size());
if((int)diff.size() == 2){
tchk[diff[0]] = tchk[diff[1]] = 1;
}
if((int)diff.size() == 1){
ocnt[pre] += 1;
}
return;
}
if(x == -1) return;
self(self, way[x][0], x);
diff.push_back(x);
self(self, way[x][1], x);
diff.pop_back();
if(way[x][0] >= 0) ocnt[x] += ocnt[way[x][0]];
if(way[x][1] >= 0) ocnt[x] += ocnt[way[x][1]];
};
dfs(dfs, 0, -1);
if(mn == 0) return 0;
if(mn >= 3) return 1;
if(mn == 2){
for(int i = 0; i < n; ++i){
if(!tchk[i]){
return 1;
}
}
return 0;
}
int can = 0;
auto onesol = [&](auto&&self, int x)->void{
if(way[x][0] < 0) return;
if(ocnt[x] != ocnt[way[x][0]]) return;
if(!tchk[x]){
can = 1;
return;
}
self(self, way[x][0]);
};
onesol(onesol, 0);
int can2 = 1, tcnt = 0, ed = 0;
for(int i = 0; i < n; ++i){
if(way[i][0] >= 0 && way[i][1] >= 0) can2 = 0;
tcnt += (way[i][0] == -2) + (way[i][1] == -2);
if(way[i][0] < 0 && way[i][1] < 0){
ed |= (way[i][0] == -2 || way[i][1] == -2);
}
}
if(can || (can2 && tcnt == 1 && ed)) return 1;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
304 KB |
Output is correct |
23 |
Correct |
1 ms |
304 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
304 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
304 KB |
Output is correct |
23 |
Correct |
1 ms |
304 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
81 ms |
26564 KB |
Output is correct |
28 |
Correct |
82 ms |
26572 KB |
Output is correct |
29 |
Correct |
86 ms |
26572 KB |
Output is correct |
30 |
Correct |
102 ms |
40644 KB |
Output is correct |
31 |
Correct |
107 ms |
40648 KB |
Output is correct |
32 |
Correct |
90 ms |
26556 KB |
Output is correct |
33 |
Correct |
86 ms |
26568 KB |
Output is correct |
34 |
Correct |
87 ms |
26512 KB |
Output is correct |
35 |
Correct |
86 ms |
26480 KB |
Output is correct |
36 |
Correct |
86 ms |
26680 KB |
Output is correct |
37 |
Correct |
85 ms |
26548 KB |
Output is correct |
38 |
Correct |
85 ms |
26596 KB |
Output is correct |
39 |
Correct |
83 ms |
26576 KB |
Output is correct |
40 |
Correct |
83 ms |
26572 KB |
Output is correct |
41 |
Correct |
83 ms |
26572 KB |
Output is correct |
42 |
Correct |
90 ms |
26572 KB |
Output is correct |
43 |
Correct |
85 ms |
26572 KB |
Output is correct |
44 |
Correct |
90 ms |
26564 KB |
Output is correct |
45 |
Correct |
84 ms |
26556 KB |
Output is correct |
46 |
Correct |
85 ms |
26552 KB |
Output is correct |
47 |
Correct |
90 ms |
29644 KB |
Output is correct |
48 |
Correct |
90 ms |
29720 KB |
Output is correct |
49 |
Correct |
91 ms |
29640 KB |
Output is correct |
50 |
Correct |
89 ms |
29620 KB |
Output is correct |