Submission #698579

#TimeUsernameProblemLanguageResultExecution timeMemory
698579bogdanvladmihaiCat in a tree (BOI17_catinatree)C++14
100 / 100
102 ms20416 KiB
#include <bits/stdc++.h> using namespace std; int N, K; vector<vector<int>> G, children; pair<int, int> dfs(int u, int D) { if (children[u].empty()) { return make_pair(1, 1); } pair<int, int> answer = dfs(children[u][0], D); answer = (answer.second == D ? make_pair(answer.first + 1, 0) : answer); for (int i = 1; i < (int)children[u].size(); i++) { auto child = dfs(children[u][i], D); answer.first += child.first; if (answer.second + child.second >= D) { answer.second = min(answer.second, child.second); } else { answer.first--; answer.second = max(answer.second, child.second); } } answer.second++; return answer; } int main() { cin >> N >> K; G.resize(N); children.resize(N); for (int i = 1; i < N; i++) { int v; cin >> v; children[v].push_back(i); } cout << dfs(0, K).first << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...