
本文共 3323 字,大约阅读时间需要 11 分钟。
���������������������������������������������������������������������������������k���������������������������������������������������������������������������������������������������
������������
������������������������������f���������f[v]���������������������������������������������������������������������������������������������������������������������������������������������������������������������������f.values������������������������������
���������������������������������������������������������������������������������������������������f[u]���������������������������������f���������������������f���������������������������
������������
#include#include using namespace std;void dfs(int u, int fa){ if(d[u] == 1 && u != 1) { dp[u] = 0; return; } int max_depth = 0; for(int i = h[u]; i != -1; i = ne[i]) { int v = e[i]; if(v == fa) continue; dfs(v, u); max_depth = max(max_depth, dp[v] + 1); dp[u] = min(dp[u], dp[v] + 1); }}void dfs2(int u, int fa){ vector children; for(int i = h[u]; i != -1; i = ne[i]) { int v = e[i]; if(v == fa) continue; dfs2(v, u); children.push_back(dp[v]); if(u == 1 && max_depth < max(max_depth, dp[v])) { max_depth = max(max_depth, dp[v]); } } if(u == 1) { v.push_back(max_depth); sort(v.begin(), v.end()); if(!v.empty()) { int res = max(res, v.back() + 2); } }}int main(){ define the tree structure and perform the DFS accordingly}
������������������
������������
���������������n���������������������������������������������������������������������������������
������������
������������������������u������������1���������f[u]���������������������������������������������������������k���������������
������������
������������vector���algorithm���������������������������������������������������������������������
������������
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
������������������������������������������k���������������������������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
