이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 (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[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... |