# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1058657 | Ignut | 참나무 (IOI23_beechtree) | C++17 | 74 ms | 20424 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/* Ignut
started: 14.08.2024
now: 14.08.2024
████████████████████████████████████████████████████████████████████
████████████████████████████████ ████████████████████████████████
██████████████████████████████ ██████████████████████████████
██████ ██████████████████ ██████████████████ ██████
██████ ██████████████ ██████████████ ██████
██████ ██ ████████████ ████████████ ██ ██████
██████ ████ ██████████ ██████████ ████ ██████
██████ ████ ██████████ ██████████ ████ ██████
██████ ████ ██████████ ██████████ ██████ ██████
██████ ██████ ██████████ ██████████ ██████ ██████
██████ ██████ ████████ ████████ ██████ ██████
██████ ██████ ██████ ██████ ██████ ██████
██████ ████ ████ ████ ████ ██████
██████ ██████████ ████ ██████████ ██████
██████ ██ ██████ ████████ ██████ ██ ██████
██████ ██████ ████████ ██████ ██████
██████ ██ ██ ██████
██████████████████████ ████ ████ ██████████████████████
████████████████████████ ██ ██ ████████████████████████
██████████████████████████ ██████████████████████████
██████████████████████████████ ██████████████████████████████
████████████████████████████████████████████████████████████████████
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 2e5 + 123;
int n;
vector<int> tree[MAXN];
vector<int> p;
vector<int> c;
vector<int> res;
int cnt[MAXN] = {};
int depth[MAXN];
bool Check(vector<int> &lst, int root) {
sort(lst.begin(), lst.end());
do {
bool ok = true;
for (int i = 0; i < lst.size(); i ++) {
int v = lst[i];
int par = cnt[c[v]];
int vert = (par == 0 ? root : lst[par - 1]);
if (p[v] != vert) {
ok = false; break;
}
cnt[c[v]] ++;
}
for (int v : lst) cnt[c[v]] = 0;
if (ok) return true;
} while (next_permutation(lst.begin(), lst.end()));
return false;
}
vector<int> dfs(int v) {
vector<int> lst = {};
for (int to : tree[v])
if (to != p[v])
for (int u : dfs(to))
lst.push_back(u);
res[v] |= Check(lst, v);
lst.push_back(v);
return lst;
}
void dfs0(int v, int d) {
depth[v] = d;
for (int to : tree[v])
if (to != p[v])
dfs0(to, d + 1);
}
vector<int> beechtree(int N, int M, vector<int> P, vector<int> C) {
n = N; p = P; c = C;
res.assign(N, 0);
if (N <= 8) {
// cout << "brute\n";
for (int i = 1; i < N; i ++) {
tree[i].push_back(P[i]);
tree[P[i]].push_back(i);
}
dfs0(0, 0);
dfs(0);
return res;
}
vector<int> v1, v2;
for (int i = 1; i < N; i ++) {
if (p[i] == 0) v1.push_back(i);
else v2.push_back(i);
res[i] = 1;
}
set<int> st;
for (int v : v1) {
st.insert(c[v]);
}
if (st.size() != v1.size())
return res;
set<int> st2;
for (int v : v2) st2.insert(c[v]);
if (st2.size() > 1) return res;
if (st2.empty()) {
res[0] = 1; return res;
}
int val = *st2.begin();
int prv = st.size();
st.insert(val);
if (st.size() > prv) return res;
res[0] = 1;
return res;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |