Submission #704680

#TimeUsernameProblemLanguageResultExecution timeMemory
704680Ronin13Cat in a tree (BOI17_catinatree)C++14
0 / 100
1 ms468 KiB
#include <bits/stdc++.h> #define ll long long #define f first #define s second #define pii pair<int,int> #define pll pair<ll,ll> #define pb push_back #define epb emplace_back using namespace std; const int nmax = 2000 + 1; vector <vector <pii> > cent(nmax); vector <bool> marked(nmax); vector <int> sz(nmax); vector <int> mx(nmax); vector <vector <int> > g(nmax); vector <int> cur(nmax, 1e9); int d[nmax][nmax]; void DFS(int v, int ind, int e = -1){ for(int to : g[v]){ if(to == e) continue; d[to][ind] =d[v][ind] + 1; DFS(to, ind, v); } } vector <pii> vv; void stupidguy(int v, int d, int e = -1){ vv.pb({d, v}); for(int to : g[v]){ if(to == e) continue; stupidguy(to, d + 1, v); } } vector <int> a; int getmn(int x){ int cur = 1e9; for(int to : a){ cur = min(cur, d[to][x]); } return cur; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int D; cin >> D; for(int i = 1; i < n; i++){ int x; cin >> x; g[x].pb(i); g[i].pb(x); } for(int i = 0; i < n; i++) DFS(i, i); sort(vv.begin(), vv.end()); int ans = 0; stupidguy(0, 0); for(int i = vv.size() - 1; i >= 0; i--){ int x = vv[i].s; if(getmn(x) >= D){ ans++; a.pb(x); } } cout << ans; return 0; } /* - - - - - - - - - - - - - - | ## | | # ## # | | ##### ## ##### | | # ## # | | ## | | ##########################| | ## | | # ## # | | ##### ## ##### | | # ## # | | ## | - - - - - - - - - - - - - - */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...