제출 #1115904

#제출 시각UTC-0아이디문제언어결과실행 시간메모리
11159042024-11-21 03:43:31vjudge1Cat in a tree (BOI17_catinatree)C++17
100 / 100
66 ms19148 KiB
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[200000];
pair<int, int> dp[200000];
int D;
void DFS(int u) {
vector<int> Q;
for (int v : adj[u]) {
DFS(v); dp[u].first += dp[v].first;
Q.push_back(dp[v].second + 1);
}
sort(Q.begin(), Q.end(), greater<>());
if (Q.empty()) dp[u] = {1, 0};
else if (Q.size() == 1) {
if (Q[0] >= D) ++dp[u].first, dp[u].second = 0;
else dp[u].second = Q[0];
}
else {
while (Q.size() > 1 && Q[Q.size() - 1] + Q[Q.size() - 2] < D) --dp[u].first, Q.pop_back();
dp[u].second = Q.back();
if (dp[u].second >= D) ++dp[u].first, dp[u].second = 0;
}
// cout << u << ' ' << dp[u].first << ' ' << dp[u].second << '\n';
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...