Submission #291216

#TimeUsernameProblemLanguageResultExecution timeMemory
291216BlagojceCat in a tree (BOI17_catinatree)C++11
51 / 100
1088 ms14192 KiB
#include <bits/stdc++.h> #define fr(i, n, m) for(int i = (n); i < (m); i ++) #define pb push_back #define st first #define nd second #define pq priority_queue #define all(x) begin(x), end(x) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; const ll inf = 1e18; const ll mod = 1000000007; const ld eps = 1e-13; const ld pi = 3.14159265359; mt19937 _rand(time(NULL)); clock_t timer = clock(); const int mxn = 2e5; int n, d; vector<int> g[mxn]; int depth[mxn]; void dfs(int u, int p){ for(auto e : g[u]){ if(e == p) continue; depth[e] = depth[u] + 1; dfs(e, u); } } bool deleted[mxn]; void _remove(int u, int p, int dis){ deleted[u] = true; if(dis == d) return; for(auto e : g[u]){ if(e == p) continue; _remove(e, u, dis + 1); } } void solve(){ cin >> n >> d; --d; fr(i, 0, n-1){ int x; cin >> x; g[x].pb(i+1); g[i+1].pb(x); } dfs(0, 0); vector<int> v; fr(i, 0, n) v.pb(i); sort(all(v), [](const int &i, const int &j){ return depth[i] > depth[j]; }); int ans = 0; for(auto u : v){ if(deleted[u]) continue; _remove(u, u, 0); ++ans; } cout<<ans<<endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...