# Smooth engineering hdu1863

Source: Internet
Author: User

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1863

# Include <iostream> // The Problem of the Minimum Spanning Tree
# Include <algorithm>
# Include <cstdio>
Using namespace STD;
Int s [4951];

Struct Stu
{
Int X;
Int y;
Int DIS;
} DF [2, 4951];

Int CMP (stu a, Stu B)
{
Return A. Dis <B. DIS;
}

Int find (int)
{
Int r =;
While (R! = S [R])
R = s [R];
Return R;
}

Void Merge (int A, int B)
{
If (A> B)
S [B] =;
Else
S [a] = B;

}
Int main ()
{
Int n, m, Q, I, j, sum;
While (scanf ("% d", & N, & M )! = EOF)
{
If (n = 0) continue;
For (I = 0; I <n; I ++)
{
Scanf ("% d", & DF [I]. X, & DF [I]. Y, & DF [I]. Dis );
}
Sort (DF, DF + N, CMP );
For (I = 1; I <= N; I ++)
S [I] = I;
Q = 0;
Sum = 0;
For (I = 0; I <n; I ++)
{
Int A = find (DF [I]. X );
Int B = find (DF [I]. y );
If (! = B)
{
Sum + = DF [I]. DIS;
Q ++;
Merge (A, B );
}
}
If (q = m-1)
Printf ("% d/N", sum );
Else
Printf ("? /N ");
}
}

Related Keywords:

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.