Submission #170347

#TimeUsernameProblemLanguageResultExecution timeMemory
170347ngmhCompany Planning (TOKI14_company)C++11
100 / 100
280 ms14372 KiB
#include <bits/stdc++.h> using namespace std; int n, m, mini, maxi, medi, t; vector<int> adj[100005]; int yeets(int x, int k){ if(adj[x].size() == 0) return 1; priority_queue<int> cs; for(auto it : adj[x]) cs.push(yeets(it, k)); int t = 0; for(int i = 1; i <= k; i++){ if(cs.size() == 0) break; t += cs.top(); cs.pop(); } return t+1; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; if(m == 1){ cout << 0; return 0; } for(int i = 2; i <= n; i++){ cin >> t; adj[t].push_back(i); } mini = 1; maxi = n; while(mini < maxi){ medi = mini+(maxi-mini)/2; if(yeets(1, medi) >= m) maxi = medi; else mini = medi+1; } cout << mini; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...