제출 #970022

#제출 시각아이디문제언어결과실행 시간메모리
970022dubabubaCat in a tree (BOI17_catinatree)C++14
100 / 100
95 ms23376 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; #define ff first #define ss second #define MP make_pair template<typename T> void ono_min(T &MIN, T CMP) { if(MIN > CMP) MIN = CMP; } template<typename T> void ono_max(T &MAX, T CMP) { if(MAX < CMP) MAX = CMP; } const int inf = 1e9 + 10; const int mxn = 2e5 + 10; int dis[mxn], dp[mxn]; vector<int> adj[mxn]; int n, d, ans; void dfs(int u, int p = 0) { int mx = inf, cnt = 0; for(int v : adj[u]) { if(v == p) continue; dfs(v, u); if(mx + dis[v] >= d) { cnt += dp[v]; ono_min(mx, dis[v]); } else { cnt += dp[v] - 1; ono_max(mx, dis[v]); } } if(mx >= d) { dis[u] = 1; dp[u] = cnt + 1; } else { dis[u] = mx + 1; dp[u] = cnt; } ono_max(ans, dp[u]); } int main() { cin >> n >> d; for(int i = 1, j; i < n; i++) { cin >> j; adj[i].push_back(j); adj[j].push_back(i); } dfs(0); cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...