Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1879
# Include <iostream> // 2243673 2010-03-24 20:56:41 accepted 1879 375 Ms 320 k 1070 B C ++ regret
# Include <algorithm> // After modifying the AC three times, why is the code less efficient?
# Include <cstdio>
# Include <cmath>
Using namespace STD;
Int s [4991];
Struct Stu
{
Int X;
Int y;
Int DIS;
} DF [4991]; // you do not know how to calculate the definition of 4591 here.
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, a, B, c, d, sum, M;
While (scanf ("% d", & N )! = EOF & n! = 0)
{
M = N * (N-1)/2; // At the beginning, n = 3 is also wrong.
For (INT I = 0; I <m; I ++)
{
Scanf ("% d", & A, & B, & C, & D );
If (D = 0)
{
DF [I]. x =;
DF [I]. Y = B;
DF [I]. Dis = C;
}
Else
{
DF [I]. x =;
DF [I]. Y = B;
DF [I]. Dis = 0;
}
}
Sort (DF, DF + M, CMP );
For (INT I = 1; I <= N * (n-1)/2; I ++)
S [I] = I;
Sum = 0;
For (INT I = 0; I <n * (n-1)/2; I ++)
{
Int A = find (DF [I]. X );
Int B = find (DF [I]. y );
If (! = B)
{
Sum + = DF [I]. DIS;
Merge (A, B );
}
}
Printf ("% d/N", sum );
}
}