Submission #797846

#TimeUsernameProblemLanguageResultExecution timeMemory
797846bonkCat in a tree (BOI17_catinatree)C++14
0 / 100
3 ms5716 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 2; vector<int>adj[N]; vector<int>vis(N, 0); int freq[N]; int n, d; void dfs(int prev, int cur){ freq[vis[cur]]++; for(auto &nxt: adj[cur]){ if(prev == nxt) continue; vis[nxt] = (vis[cur] + 1) % d; dfs(cur, nxt); } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> d; for(int i = 1; i < n; i++){ int p; cin >> p; adj[i].push_back(p); adj[p].push_back(i); } for(int i = 0; i <= n; i++){ if(adj[i].size() == 1){ dfs(-1, i); break; } } int ans = 0; for(int i = 0; i < d; i++){ ans = max(ans, freq[i]); } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...