Submission #1039040

#TimeUsernameProblemLanguageResultExecution timeMemory
1039040HanksburgerCat in a tree (BOI17_catinatree)C++17
0 / 100
2 ms5156 KiB
#include <bits/stdc++.h> using namespace std; vector<int> adj[200005]; int n, d, s, x; int f(int u) { int m=1e9; for (int v:adj[u]) { int r=f(v); if (m!=1e9 && m+r+2<d) s--; else m=min(m, r); } if (m+1>=d) s++, m=-1; return m+1; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> d; for (int i=1; i<n; i++) { cin >> x; adj[x].push_back(i); } f(0); cout << s; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...