제출 #865431

#제출 시각아이디문제언어결과실행 시간메모리
865431maks007Cat in a tree (BOI17_catinatree)C++14
0 / 100
0 ms348 KiB
// Bismi ALlah #include "bits/stdc++.h" using namespace std; #define int long long signed main () { int n, d, cnt = 0; cin >> n >> d; vector <int> g[n], depth(n); function <void(int,int,int,int)> dfs=[&](int v, int p, int opt, int deep) { depth[v] = deep; if(deep % d == 0 && opt) cnt ++; for(auto u : g[v]) { if(u == p) continue; dfs(u, v, opt, deep+1); } }; for(int i = 1; i < n; i ++) { int p; cin >> p; g[i].push_back(p); g[p].push_back(i); } dfs(0, -1, 0, 0); int mx = max_element(depth.begin(), depth.end()) - depth.begin(); dfs(mx, -1, 1, 0); cout << cnt; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...