# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
163536 | Kalam | Cat in a tree (BOI17_catinatree) | C++11 | 121 ms | 20344 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.
// KALAM
# include<bits/stdc++.h>
using namespace std;
const int N = 200000 + 77;
int n , d , dp[N] , dist[N];
vector < int > adj[N];
void dfs(int v) {
vector < int > V;
for(int u : adj[v])
dfs(u) , V.push_back(dist[u] + 1) , dp[v] += dp[u];
if(V.empty()) { dp[v] = 1; dist[v] = 0; return ; }
sort(V.begin() , V.end() , [&](int x , int y) { return x > y; });
while(V.size() > 1 && V.back() + V[(int) V.size() - 2] < d) -- dp[v] , V.pop_back();
if(V.empty() || V.back() >= d) ++ dp[v] , V.push_back(0);
dist[v] = V.back();
}
int main() {
scanf("%d %d" , & n , & d);
for(int x , i = 2;i <= n;++ i)
scanf("%d" , & x) , adj[x + 1].push_back(i);
dfs(1);
printf("%d\n" , dp[1]);
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... |