이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "beechtree.h"
using namespace std;
using pii = pair<int, int>;
using piii = tuple<int, int, int>;
vector<int> T[202020], C;
priority_queue<piii> Q;
int S[202020], I[202020];
set<pii> P1[202020];
set<piii> P2[202020];
int n, m;
bool dfs(int u, vector<int> &A) {
bool f = 1;
P1[u].emplace(I[u], u);
for (int &v: T[u]) {
auto it = P2[u].emplace(C[v], I[v], u).first;
if (it != P2[u].begin() && get<0>(*prev(it)) == C[v]) f = 0;
if (next(it) != P2[u].end() && get<0>(*next(it)) == C[v]) f = 0;
}
for (int &v: T[u]) {
f &= dfs(v, A);
if (P1[u].size() < P1[v].size()) {
swap(P1[u], P1[v]); swap(P2[u], P2[v]);
}
for (auto [i, w]: P1[v]) {
auto it1 = P1[u].emplace(i, w).first;
for (int &x: T[w]) {
auto it2 = P2[u].emplace(C[x], I[x], x).first;
if (next(it2) != P2[u].end() && get<0>(*next(it2)) == C[x]) {
if (next(it1) == P1[u].end() || next(it1)->second != get<2>(*next(it2))) f = 0;
}
if (it1 != P1[u].begin()) {
if (it2 == P2[u].begin() || get<0>(*prev(it2)) != C[x] \
|| get<2>(*prev(it2)) != prev(it1)->second) f = 0;
}
}
}
}
return A[u] = f;
}
vector<int> beechtree(int n, int m, vector<int> P, vector<int> C) {
::C = C; ::n = n; ::m = m;
int i;
for (i = 1; i < n; i++) {
T[P[i]].push_back(i);
}
fill(S, S + n, 1);
for (i = n - 1; i >= 1; i--) {
S[P[i]] += S[i];
}
Q.emplace(S[0], 0, 0);
for (i = 0; !Q.empty(); i++) {
auto [_, j, v] = Q.top();
I[v] = i; Q.pop();
for (int &w: T[v]) {
Q.emplace(S[w], i, w);
}
}
vector<int> A(n);
dfs(0, A);
return A;
}
컴파일 시 표준 에러 (stderr) 메시지
beechtree.cpp: In function 'bool dfs(int, std::vector<int>&)':
beechtree.cpp:46:17: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
46 | return A[u] = f;
# | 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... |