Submission #606744

#TimeUsernameProblemLanguageResultExecution timeMemory
606744socpiteCat in a tree (BOI17_catinatree)C++17
0 / 100
1 ms212 KiB
#include<bits/stdc++.h> using namespace std; #define f first #define s second typedef long long ll; const int maxn = 105; const int mod = 1e9+7; int d[maxn]; vector<int> tree[maxn]; int n, D; stack<int> q; void dfs(int x, int p, int dep){ d[x]=-1; for(auto v: tree[x]){ if(v==p)continue; if(!dep){ d[v]--; if(d[v] <= 1)q.push(v); } else dfs(v, x, dep-1); } } int main(){ cin >> n >> D; for(int i = 1; i < n; i++){ int x; cin >> x; tree[x].push_back(i); tree[i].push_back(x); d[x]++; d[i]++; } for(int i = 0; i < n; i++)if(d[i]==1){ q.push(i); } int ans= 0; while(!q.empty()){ auto x = q.top(); q.pop(); if(d[x] < 0)continue; ans++; dfs(x, -1, D-1); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...