이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "beechtree.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> t, depth;
vector<vector<int>> ch;
vector<set<int>> ch_colors;
bool orden(int x, int y){
if (ch_colors[x].size() != ch_colors[y].size())
return ch_colors[x].size() < ch_colors[y].size();
return x > y;
}
void dfs(int u){
for (int v : ch[u]){
dfs(v);
depth[u] = max(depth[u], depth[v] + 1);
if (t[v] == 0)
t[u] = 0;
}
if (depth[u] != 2){
if (depth[u] > 2)
t[u] = 0;
return;
}
vector<int> ord = ch[u];
ord.push_back(u);
sort(ord.begin(), ord.end(),orden);
if (ord.back() != u)
t[u] = 0;
for (int i = 0; i + 1 < (int)ord.size(); ++i)
{
int x = ord[i], y = ord[i + 1];
for (int c : ch_colors[x])
{
if (!ch_colors[y].count(c))
t[u] = 0;
}
}
}
vector<int> beechtree(int N, int M, vector<int> P, vector<int> C){
t.assign(N, 1);
ch.assign(N, {});
ch_colors.resize(N);
for (int v = 1; v < N; ++v){
int u = P[v], c = C[v];
if (ch_colors[u].count(c))
t[u] = false;
ch[u].push_back(v);
ch_colors[u].insert(c);
}
depth.assign(N, 0);
dfs(0);
return t;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |