HDU 2196 computer (tree DP)

Source: Internet
Author: User

Question Link

It is to give you a tree with a certain weight for each edge, and then let you find the maximum distance that each vertex can reach.

Analysis:

This question is still a bit dizzy. I posted my analysis on it and analyzed it thoroughly.

First, we use 1 as the root node for a DFS traversal. During traversal, we can find out the maximum distance and the next distance that can be reached from the root node I to the subtree, and the two distances are not in the same branch. Then we start the DFS traversal from the root node for the second time. At this time, we need to determine that for a node I, in addition to the shortest distance in the direction of the subtree, can I use the parent node to make it farther away? For this operation, we only need to access the maximum distance that the parent node can reach, then you can connect to the node, but there is a problem -- that is, the maximum distance of the parent node may pass through the current node, therefore, we need to determine whether the current node is on the longest branch of the parent node. If so, we need to change to another branch, and if it is the farthest, in fact, this is the first time that the remote path obtained in DFS is not in the same branch as the farthest path. If the path is not transferred, then we can directly connect to the farthest path of the parent node for transfer.

HDU 2196 computer (tree DP)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.