#include using namespace std; const int oo = 0x3f3f3f3f; const double eps = 1e-9; const double PI = 2.0 * acos(0.0); typedef long long ll; typedef unsigned long long ull; typedef pair pii; typedef vector vi; typedef vector vs; #define sz(c) int((c).size()) #define all(c) (c).begin(), (c).end() #define FOR(i,a,b) for (int i = (a); i < (b); i++) #define FORS(i,a,b,s) for (int i = (a); i < (b); i=i+(s)) #define FORD(i,a,b) for (int i = int(b)-1; i >= (a); i--) #define FORIT(i,c) for (__typeof__((c).begin()) i = (c).begin(); i != (c).end(); i++) int pre[1000*1000]; int nc[1000*1000]; int branch_depth(int i, int & bn){ if (i == 0) {bn = i; return 0;} if (nc[i] > 1) {bn = i; return 0;} return 1 + branch_depth(pre[i], bn); } int main(){ //cout << 1 << endl; //return 0; int N,K; cin >> N >> K; FOR(i,1,N){ cin >> pre[i]; nc[pre[i]]++; } int R = 0; vi leafs; FOR(i,0,N){ if (nc[i]) continue; // only do this for leafs leafs.push_back(i); R++; } while (R >= 2){ int minlen = oo; int bestL = -1; int bestBN = -1; // search for next leaf to take FOR(l,0,sz(leafs)){ int bn; int d = branch_depth(leafs[l],bn); if (d < minlen){ minlen = d; bestL = l; bestBN = bn; } } if (minlen > K){ cout << R << endl; return 0; } K-=minlen; R--; nc[bestBN]--; // the branching node now has one fewer successors leafs.erase(leafs.begin() + bestL); } cout << R << endl; return 0; }