이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "beechtree.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define ll long long
#define ff first
#define ss second
#define vi vector<int>
const int N = 3005;
const ll INF = 1e18;
vector<int> g[N], s[N];
vi res;
int antidep[N], col[N], n, m, par[N];
bool ok = 1;
void dfs(int v){
set<int> s;
antidep[v] = 0;
int co = 0, node;
for(int u: g[v]){
dfs(u);
par[u] = v;
s.insert(col[u]);
antidep[v] = max(antidep[u] + 1, antidep[v]);
if(g[u].size() > 0) co++, node = u;
}
// cout << v << ' ' << antidep[v] << '\n';
if(g[v].size() == 0){
res[v] = 1;
}else if(s.size() == g[v].size() && antidep[v] == 1){
res[v] = 1;
}else{
if(antidep[v] > 2){
res[v] = 0;
}else{
if(co == 1){
for(int x: g[node]){
s.insert(col[x]);
}
if(s.size() == g[v].size()){
res[v] = 1;
}else{
res[v] = 0;
}
}else{
res[v] = 0;
}
}
}
}
std::vector<int> beechtree(int nn, int mm, std::vector<int> P, std::vector<int> C)
{n=nn, m=mm;
res.resize(n);
for(int i = 1; i < n; ++i){
g[P[i]].pb(i);
col[i] = C[i];
}
// dfs(0);
// bool ok = 1;
// res[n - 1] = 1;
// for(int i = n - 2; i >= 0; --i){
// if(ok == 0){
// res[i] = ok;
// }else if(C[i] != C[i + 1]){
// res[i] = 1;
// ok = 0;
// }else{
// res[i] = 1;
// }
// }
dfs(0);
return res;
}
# | 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... |