版本比较
树形dp与树的直径
正文
增加 2 行删除 2 行
118 行未改动全部展开119120121122123123124125126127113 行未改动全部展开241242243244245245246247248249250 行未改动全部展开118 行未改动全部展开答案就是 $\max(\{d1[u] + d2[u]\})$ 。
::::info[code]```cpp#include <bits/stdc++.h> #include <bits/stdc++.h>using namespace std;const int maxn = 1e5 + 10;int n, d;int d1[maxn], d2[maxn];113 行未改动全部展开 if(diameter.find(parent[top.second]) == diameter.end()){ leaf.push({top.first - 1 , parent[top.second]}); } }
j = T; ans += 1ll * ds[T] * (ds[T] - 1) >> 1; while(j != S){ ABC.push_back({S , j , j});250 行未改动全部展开