이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <queue>
#include <bitset>
#include <vector>
#include <set>
using namespace std;
const int MAXN = 1580;
int depth[MAXN];
vector<int> edg[MAXN];
bitset<MAXN> bs;
signed main() {
int n, d;
cin >> n >> d;
vector<pair<int, int>> vs;
for (int i = 1; i < n; ++i) {
int rt;
cin >> rt;
edg[rt].push_back(i);
depth[i] = depth[rt] + 1;
vs.push_back({depth[i], i});
edg[i].push_back(rt);
}
sort(vs.begin(), vs.end());
int ans = 0;
while (vs.size()) {
int v = vs.back().second;
vs.pop_back();
if (!bs[v]) {
++ans;
queue<pair<int, int>> q;
q.push({v, 0});
bs[v] = 1;
while (q.size()) {
auto [u, t] = q.front();
q.pop();
if (t + 1 < d) {
for (auto w : edg[u]) {
if (!bs[w]) {
bs[w] = 1;
q.push({w, t + 1});
}
}
}
}
}
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |