HDU 1879 continued smooth Engineering

Source: Internet
Author: User

Link: HDU 1879

The paths of this question are divided into the repaired and unrepaired ones. Therefore, you only need to change the cost of the repaired paths to 0, which is converted into the general minimum spanning tree question.

# Include <cstdio> # include <algorithm> using namespace STD; int f [105], n, m; struct Stu {int A, B, C;} t [5500]; int CMP (struct Stu X, struct Stu y) {return X. c <Y. c;} int find (int x) {If (X! = F [x]) f [x] = find (F [x]); Return f [X];} int KRUS () {int I, K = 0, S = 0, x, y; for (I = 1; I <= m; I ++) {x = find (T [I]. a); y = find (T [I]. b); If (X! = Y) {S + = T [I]. c; k ++; If (k = N-1) break; F [x] = y;} return s;} int main () {int I, S, Z; while (scanf ("% d", & N )! = EOF) {If (n = 0) break; M = N * (n-1)/2; for (I = 1; I <= m; I ++) {scanf ("% d", & T [I]. a, & T [I]. b, & T [I]. c, & Z); If (Z = 1) // change the cost of the repaired road to 0 T [I]. C = 0 ;}for (I = 1; I <= N; I ++) f [I] = I; sort (t + 1, t + 1 + m, CMP); s = KRUS (); printf ("% d \ n", S);} return 0 ;}


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.