# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
149827 | | mit한의대지망생 (#200) | Bulb Game (FXCUP4_bulb) | C++17 | | 210 ms | 46352 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bulb.h"
#include <vector>
using namespace std;
vector<int> L, R;
int n;
vector<int> ch[300001];
int dep[300001];
bool imp[300001];
int need[300001];
int all;
void dfs(int x) {
while (ch[x].size() > 3) ch[x].pop_back();
if (L[x] < 0) {
if (L[x] == -1);
else if (ch[x].size() > 2);
else if (ch[x].size() == 2) {
imp[ch[x][0]] = imp[ch[x][1]] = 1;
}
else if (ch[x].size() == 1) {
++need[x];
++all;
if (dep[x] < n - 1) imp[ch[x][0]] = 1;
}
else {
throw 0;
}
}
else {
dep[L[x]] = dep[x] + 1;
for (int i : ch[x]) ch[L[x]].push_back(i);
dfs(L[x]);
need[x] += need[L[x]];
}
ch[x].push_back(x);
if (R[x] < 0) {
if (R[x] == -1);
else if (ch[x].size() > 2);
else if (ch[x].size() == 2) {
imp[ch[x][0]] = imp[ch[x][1]] = 1;
}
else if (ch[x].size() == 1) {
++need[x];
++all;
if (dep[x] < n - 1) imp[ch[x][0]] = 1;
}
else {
throw 0;
}
}
else {
dep[R[x]] = dep[x] + 1;
for (int i : ch[x]) ch[R[x]].push_back(i);
dfs(R[x]);
need[x] += need[R[x]];
}
}
int FindWinner(int T, vector<int> _L, vector<int> _R) {
n = _L.size();
L = _L;
R = _R;
try {
dfs(0);
for (int i = 0; i < n; ++i) {
if (need[i] == all && !imp[i]) throw 1;
}
throw 0;
} catch (int ret) {
return ret;
}
return -1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |