# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
134953 | songc | Cat in a tree (BOI17_catinatree) | C++14 | 208 ms | 16484 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
int N, K, ans;
int D[202020], dep[202020];
vector<int> adj[202020];
vector<pii> V;
void dfs(int u, int p, int d){
if (D[u] >= d) return;
D[u] = d;
for (int v : adj[u]) if (v != p) dfs(v, u, d-1);
}
int main(){
scanf("%d %d", &N, &K);
for (int i=2; i<=N; i++){
int x;
scanf("%d", &x);
adj[x+1].push_back(i);
adj[i].push_back(x+1);
dep[i] = dep[x+1] + 1;
}
for (int i=1; i<=N; i++) V.push_back(pii(-dep[i], i));
sort(V.begin(), V.end());
for (int i=0; i<N; i++){
int u = V[i].second;
if (D[u]) continue;
ans++;
dfs(u, 0, K);
}
printf("%d\n", ans);
return 0;
}
Compilation message (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... |