Solution 20181029 test: T4 Ambassador

Source: Internet
Author: User
There are many ideas for this question. Here we only introduce one idea: the general idea of the Kruskal algorithm: First sorting, then using and querying the connected edge of the set,Final output maximum Edge Weight.
Sort (E + 1, E + 1 + M, CMP); For (INT I = 1; I <= m; ++ I) {f = find (E [I]. f); t = find (E [I]. t); If (F! = T) {B [f] = T; ++ CNT; W = find (1); If (t = W) {for (Int J = 2; j <= N; ++ J) {If (OK [J] = false & find (j) = W) {ans [J] = E [I]. w; OK [J] = true ;}}if (CNT = N-1) {break ;}}}}
Q1: Why is Kruskal used in this question )? A1: you only need to determine whether each vertex is connected to $1 $ when the maximum spanning tree is generated. If yes, then his answer is the current edge (because the edge is arranged in ascending order of weight, and the current edge is the smallest edge between the current vertex and $1 $ ).

Solution 20181029 test: T4 Ambassador

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.