codeforces1453 E. Dog Snacks
发布日期:2021-05-14 16:55:12 浏览次数:18 分类:精选文章

本文共 3323 字,大约阅读时间需要 11 分钟。

���������������������������������������������������������������������������������k���������������������������������������������������������������������������������������������������

������������

������������������������������f���������f[v]���������������������������������������������������������������������������������������������������������������������������������������������������������������������������f.values������������������������������

���������������������������������������������������������������������������������������������������f[u]���������������������������������f���������������������f���������������������������

  • ������������������������������������������������
  • ������������������������������������������������������������������������������f������������������������u���f[u]������������������������������f������1���
  • ������������������������������������������������������������������������������f���������1������������f[1]������1���������������������������������f������
  • ���������������k���k���������������������f���������������������1���������������������������������������������
  • ������������

    #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
    }

    ������������������

  • ������������������������������������h���ne���������������������u���������������e���idx���������������
  • ������������������������������������������1������������������������������������������u���f������������������������������������������������������������������������f������������������������f������
  • ������������������������������������������������������������������������������������������max_depth���k���������������max_depth + 1���
  • ������������

    ���������������n���������������������������������������������������������������������������������

    ������������

    ������������������������u������������1���������f[u]���������������������������������������������������������k���������������

    ������������

    ������������vector���algorithm���������������������������������������������������������������������

    ������������

    ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

    ������������������������������������������k���������������������������������������������������������������������������������������������������������������������������������������������

    上一篇:D. Checkpoints
    下一篇:CodeForces - 1200E 哈希或kmp

    发表评论

    最新留言

    第一次来,支持一个
    [***.219.124.196]2025年04月13日 00时30分02秒