Submission #1103130

#TimeUsernameProblemLanguageResultExecution timeMemory
1103130alexddCat in a tree (BOI17_catinatree)C++17
11 / 100
3 ms5712 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int INF = 1e9; int n,d,root,cnt; vector<int> con[200005]; int parent[200005],depth[200005]; int insus[200005]; void dfs(int nod, int interzis) { insus[nod]=interzis; for(int adj:con[nod]) { if(adj==parent[nod]) continue; parent[adj] = nod; dfs(adj,interzis-1); insus[nod] = max(insus[nod], insus[adj]-1); interzis = max(interzis, insus[adj]-1); } if(interzis<=0) { cnt++; insus[nod]=d; } } signed main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>d; int u; for(int i=2;i<=n;i++) { cin>>u; u++; con[i].push_back(u); con[u].push_back(i); } root=1; for(int i=1;i<=n;i++) if((int)con[i].size()>1) root=i; //cerr<<root<<" root\n"; dfs(root,-1); cout<<cnt; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...