# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
550441 | Jarif_Rahman | Cat in a tree (BOI17_catinatree) | C++17 | 72 ms | 23404 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>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int n, D;
vector<vector<int>> v;
vector<pair<int, int>> dp;
void dfs(int nd){
for(int x: v[nd]) dfs(x);
int d = 1e9, s = 0;
vector<int> sth;
for(int x: v[nd]) s+=dp[x].f, sth.pb(dp[x].sc+1);
sort(sth.begin(), sth.end());
if(!sth.empty()) d = sth[0];
for(int i = 1; i < sth.size(); i++) if(sth[i]+sth[i-1] < D) s--, d = sth[i];
dp[nd].f = s;
if(d >= D) dp[nd].f++, dp[nd].sc = 0;
else dp[nd].sc = d;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> D;
v.resize(n);
dp.resize(n);
for(int i = 1; i < n; i++){
int p; cin >> p;
v[p].pb(i);
}
dfs(0);
cout << dp[0].f << "\n";
}
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... |