제출 #730397

#제출 시각아이디문제언어결과실행 시간메모리
730397iosif_andrei_Cat in a tree (BOI17_catinatree)C++14
100 / 100
116 ms20656 KiB
#include <bits/stdc++.h> using namespace std; int n, k; vector <int> g[200001]; pair <int, int> dfs(int nod = 0) { vector <int> v; int ret = 1; v.push_back(0); for (auto &i : g[nod]) { pair <int, int> aux = dfs(i); v.push_back(aux.first); ret += aux.second; } sort(v.begin(), v.end()); int i = 0; while (v.size() - i > 1 && v[i] + v[i + 1] < k) i++, ret--; return {v[i] + 1, ret}; } int main() { cin >> n >> k; for (int i = 1; i < n; i++) { int x; cin >> x; g[x].push_back(i); } cout << dfs().second; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...