Bzoj 5195 [usaco 2018 Feb] Directory Traversal

Source: Internet
Author: User

Descrtiption

Bessie, the cow, was surprisingly proficient in computers. She stored all her precious files in a folder on a cowshed computer, for example:

 
Bessie/folder1 /? File1? Folder2 /? File2 folder3 /? File3 file4

There is only one "top-level" folder called Bessie.

Bessie can browse any folder she wants to access. From a Given folder, each file can be referenced through a "relative path.

In a relative path, the symbol "..." refers to the parent directory. If Bessie is in folder2, she can reference the four files in the following path:

 
../File1file2 ../folder3/file3./../file4

Bessie wants to select a folder to minimize the sum of the relative paths of all files starting from this folder.

\ (N \ leqslant 1e5 \)

Solution

\(\,\,\,\,\,\,\,\,\,\,\,\)First, you need to understand the question surface (I will not explain it again if you don't understand it ). Typical secondary root change questions. Set\ (Len_ I? \)Is the name length of vertex I, Set\ (F_ I? \)For the sum of the length from I to all leaf points, first consider how to calculate the root F value, then consider how to use a vertex to update its son, and so on.
\(\,\,\,\,\,\,\,\,\,\,\,\)The root value is very good, because you only need to go down. Consider how to update your son.

\(\,\,\,\,\,\,\,\,\,\,\,\)For example, the string length of each vertex is equal to its own number. We first pre-process the total length from the 1st point to all the leaf points, and then consider updating the 7th point. For all the leaf points in the idea tree No. 7, point 1 must first Access Point 7 and then go down to access each point, so the total length of access to these points at = the total length of access to point 1-the number of points in the tree\ (\ Times (len_7 + 1 )\)In addition to the idea tree on the 7th, the access to the leaf point on the 7th point is the same as that on the 1st point, therefore, the total length of access to these points at = the total length of access to point 1 + (total points-number of points in point 7)\ (\ Times 3 \). Therefore, the total length of access to all leaf points at = the total length of access to point 1 + the total number of points\ (\ Times3-7 \)Number in the idea tree\ (\ Times (4 + len_7 )\).

Bzoj 5195 [usaco 2018 Feb] Directory Traversal

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.