이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <beechtree.h>
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) x.begin(), x.end()
const int N = 2e5+100;
int sz[N], dep[N], par[N], n;
vector<array<int, 2>> g[N], s[N];
vector<int> ans, COL;
set<int> C[N];
void dfs(int v){
ans[v] = 1;
sz[v] = 1;
s[v].pb({v, COL[v]});
for(auto U: g[v]){
int u = U[0], c = U[1];
dep[u] = dep[v] + 1;
par[u] = v;
dfs(u);
for(auto x: s[u]) s[v].pb(x);
sz[v] += sz[u];
ans[v] &= ans[u];
if(C[v].find(c) != C[v].end()) ans[v] = 0;
C[v].insert(c);
}
if(ans[v] == 0) return;
sort(all(g[v]), [&](const array<int, 2> &x, const array<int, 2> &y){
return sz[x[0]] > sz[y[0]];
});
for(int i = 0; i < g[v].size(); ++i){
int x = (i == 0 ? v : g[v][i - 1][0]), y = g[v][i][0];
for(auto col: C[y]){
if(C[x].find(col) == C[x].end()){
ans[v] = 0;
break;
}
}
}
if(ans[v] == 0) return;
sort(all(s[v]), [&](const array<int, 2> &x, const array<int, 2> &y){
return (dep[x[0]] == dep[y[0]] ? COL[x[0]] < COL[y[0]]: dep[x[0]] < dep[y[0]]);
});
map<int, int> colptr;
for(int i = 1; i < s[v].size(); ++i){
int u = s[v][i][0], c = s[v][i][1];
if(par[u] != s[v][colptr[c]][0]){
ans[v] = 0;
return;
}
colptr[c]++;
}
}
vector<int> beechtree(int nn, int m, vector<int> P, vector<int> CC){
COL = CC;
n = nn;
for(int i = 1; i < n; ++i){
g[P[i]].pb({i, COL[i]});
}
ans.resize(n);
dep[0] = 0;
dfs(0);
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
beechtree.cpp: In function 'void dfs(int)':
beechtree.cpp:37:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(int i = 0; i < g[v].size(); ++i){
| ~~^~~~~~~~~~~~~
beechtree.cpp:53:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(int i = 1; i < s[v].size(); ++i){
| ~~^~~~~~~~~~~~~
# | 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... |