zoukankan      html  css  js  c++  java
  • POJ 3585 Accumulation Degree-树型DP(换根DP)

    POJ 3585 Accumulation Degree

    题目传送门

    Description

    Trees are an important component of the natural landscape because of their prevention of erosion and the provision of a specific ather-sheltered ecosystem in and under their foliage. Trees have also been found to play an important role in producing oxygen and reducing carbon dioxide in the atmosphere, as well as moderating ground temperatures. They are also significant elements in landscaping and agriculture, both for their aesthetic appeal and their orchard crops (such as apples). Wood from trees is a common building material.

    Trees also play an intimate role in many of the world's mythologies. Many scholars are interested in finding peculiar properties about trees, such as the center of a tree, tree counting, tree coloring. A(x) is one of such properties.

    A(x) (accumulation degree of node x) is defined as follows:

    1. Each edge of the tree has an positive capacity.
    2. The nodes with degree of one in the tree are named terminals.
    3. The flow of each edge can't exceed its capacity.
    4. A(x) is the maximal flow that node x can flow to other terminal nodes.

    Since it may be hard to understand the definition, an example is showed below:

    img

    A(1)=11+5+8=24  
    Details: 1->2 11
      1->4->3 5
      1->4->5 8(since 1->4 has capacity of 13)
    A(2)=5+6=11    
    Details: 2->1->4->3 5
      2->1->4->5 6
    A(3)=5    
    Details: 3->4->5 5
    A(4)=11+5+10=26    
    Details: 4->1->2 11
      4->3 5
      4->5 10
    A(5)=10    
    Details: 5->4->1->2 10

    The accumulation degree of a tree is the maximal accumulation degree among its nodes. Here your task is to find the accumulation degree of the given trees.

    Input

    The first line of the input is an integer T which indicates the number of test cases. The first line of each test case is a positive integer n. Each of the following n - 1 lines contains three integers x, y, z separated by spaces, representing there is an edge between node x and node y, and the capacity of the edge is z. Nodes are numbered from 1 to n.
    All the elements are nonnegative integers no more than 200000. You may assume that the test data are all tree metrics.

    Output

    For each test case, output the result on a single line.
     

    Sample Input

    1
    5
    1 2 11
    1 4 13
    3 4 5
    4 5 10
    

    Sample Output

    26
    

    题目大意:

    有一棵有n

    个节点、n1条边的无根树,每边有一流量限制。令某一节点为根节点,向根节点灌水,最终从叶子节点流出的水量和为这一节点的最大流量。问:在做根节点的所有节点中,最大的最大流量是多少?

    分析:

      O(N^2)做法十分简单,只需以每个点为根做一遍树型DP即可;

      即:s[x]=∑min(s[son]==0?val[i]:s[son],val[i])

      而我们发现换根时,该点下方的信息是不变的,只需把其父变为其子并求出变化值即可

      其中:s[i]为预处理出子树最大流

            F[i]为以i为根的最大流

      则F[son]=s[son]+min(val,F[x]-min(val,s[son]);

      且当F[x]-min(val,s[son])=0时 即为父结点除该子节点外没有其他子节点时

      F[son]=F[x]+val+s[son]

     暂无代码

  • 相关阅读:
    Webpack4 入门手册(共 18 章)下
    npm(Node Package Manager)
    C#(99):C# 5.0 新特性(.NET Framework 4.5 与 Visual Studio 2012 )
    C#(99):四、Async和Await使异步编程更简单
    C#(99):三、.NET 4.0基于任务的异步模式(TAP),推荐使用
    C#(99):二、.NET 2.0基于事件的异步编程模式(EAP)
    C#(99):一、.NET 1.0 异步编程模型(APM)
    VS中的代码段功能
    VS在C#类文件头部添加文件注释的方法
    C#(99):C# 语言历史版本特性(C# 1.0到C# 8.0汇总)
  • 原文地址:https://www.cnblogs.com/Marcelo/p/13605234.html
Copyright © 2011-2022 走看看