COGS 2416. [Hzoi 2016] Highway construction & COGS 2419. [Hzoi 2016] Highway construction 2

Source: Internet
Author: User

Effect:

[Hzoi 2016] highway construction

Given a undirected connectivity graph with n points and m-1 group edges, where each set of edges contains a primary edge and a two-level edge (the same vertex is connected), one-level edge weights in the same set of edges must be greater than or equal to two-level edges, and a number K (k<=n-1) is given, and a spanning tree for the original image is obtained So that it contains at least one level of K-Bar and the largest Benquan value as small as possible.

[Hzoi 2016] Highway construction 2

The same as the previous one, but not necessarily the spanning tree (that is, there can be more than n-1 edge, as long as the graph is connected), in this case still make at least one of the K-level edge and the largest Benquan value as small as possible.

Solution:

Both problems can be solved using greedy algorithm, but because of the two problems on the final total number of different requirements, the use of the greedy algorithm is far from the difference.

For the first problem, you can first run the Kruskal to build the K-side, and then run to the two-level side Kruskal to build the remaining side.

This algorithm is more intuitive, but the correctness needs us to prove. But dBW god Ben did give a proof, here to pay a high tribute.

Here are some of my own proofs, first in two cases:

1. The maximum side is the first-level side

In this case, the incomplete spanning tree obtained by Kruskal must be as small as possible, so the solution obtained by this algorithm will not be worse than the optimal solution.

2. The maximum edge is a level two edge

If the Kruskal of the second pass can be replaced with a smaller edge than it is, then obviously this edge is not a level two (because the second time Kruskal has guaranteed this), but if it is a first-class edge, it is obviously not worse to replace the maximum edge with its two-level edge than with a one-step edge substitution. However, this situation has been overturned, so the solution of this algorithm will not be worse than the optimal solution.

In summary, this greedy algorithm is established.

For the second problem, you can first run to the two-level side of the Kruskal to find the minimum spanning tree, and then the weight of the former K small first-level edge into the scheme can be.

The correctness of this is even more obvious, but it still gives proof.

There are still two situations:

1. The maximum side is the first-level side

The second step has ensured that the scheme of the selected first-level edge does not have a better solution, in which case the algorithm is correct.

2. The maximum edge is a level two edge

The first step has ensured that there is no better solution for the selected two-tier edge scheme, so the algorithm is correct in this case.

In summary, this greedy algorithm is established.

This concludes the solution to the two problems.

Postscript:

The two problems are very similar, the solution also has a common point (all greedy + minimum spanning tree), but the two problems resulting in the final algorithm to produce such a huge difference is the two problems of a small gap:

The first question requires that the solution must be a spanning tree, the second one requires only connectivity, and the edge can be multiple (which is why it is not considered that the primary and two level sides are heavier).

If you question why the algorithm of the first question is not available to solve the second problem, see the second question's example.

These two questions tell us, must read the question carefully, otherwise saw after the second question did not read the question directly according to the generation Tree writes on the WA auspicious.

By the way, both questions can be answered in two points, with complexity and greed.

To support your

Initially was interested

Then it was a dream.

Ultimately the mission.

COGS 2416. [Hzoi 2016] Highway construction & COGS 2419. [Hzoi 2016] Highway construction 2

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.