This question is the same as that of poj, but the content is different ..
This question is actually quite watery. if you add a Lexicographic Order, you will be confused. Unfortunately, special judge is still absent ~
I started to know wa after reading the party. I started to judge whether to join the set, I thought that there was a high-speed path in the following process without adding it to the node. Wa proved that I was wrong... Because the Kruskal algorithm is used to judge the points in a set with it... And so on... If they are not added, they are not included in the set in the PRE array... It's quite tangled ~
# Include <stdio. h> <br/> # include <stdlib. h> <br/> # include <iostream> <br/> # include <math. h> <br/> # include <memory. h> <br/> # define n 755 <br/> using namespace STD; <br/> int N, P = 0; <br/> int pre [N]; <br/> struct edge <br/> {<br/> int X, Y; <br/> double Len; <br/>} City [N * n]; <br/> typedef struct edge node; <br/> double compute (double X1, double Y1, double X2, double Y2) <br/> {<br/> return (x1-x2) * (x1-x2) + (Y1 -Y2) * (y1-y2); <br/>}< br/> int find (int x) <br/>{< br/> while (X! = Pre [x]) <br/> X = pre [X]; <br/> return X; <br/>}< br/> void input () <br/>{< br/> int M, X, Y; <br/> P = 0; <br/> double COOR [N] [2], Len; <br/> CIN> N; <br/> for (INT I = 1; I <= N; I ++) <br/> CIN> COOR [I] [0]> COOR [I] [1]; <br/> CIN> m; <br/> for (INT I = 1; I <= N; I ++) <br/> pre [I] = I; <br/> for (INT I = 1; I <= m; I ++) <br/>{< br/> CIN> x> Y; <br/> X = find (x); <br/> Y = find (y); <br/> If (X! = Y) <br/> pre [x] = y; <br/>}< br/> for (INT I = 1; I <= N; I ++) <br/> for (Int J = I + 1; j <= N; j ++) <br/> {<br/> Len = compute (COOR [I] [0], COOR [I] [1], COOR [J] [0], COOR [J] [1]); <br/> City [p]. X = I; City [p]. y = J; <br/> City [p]. len = Len; <br/> P ++; <br/>}< br/> int CMP (const void * a, const void * B) <br/> {<br/> return (node *) A)-> Len> (node *) B)-> Len? 1:-1; <br/>}< br/> void Kruskal () <br/>{< br/> int A, B, I; <br/> qsort (city, P, sizeof (node), CMP); <br/> for (I = 0; I <p; I ++) <br/> {<br/> A = find (City [I]. x); <br/> B = find (City [I]. y); <br/> if (! = B) <br/>{< br/> pre [B] = A; <br/> cout <City [I]. x <"" <City [I]. Y <Endl; <br/>}< br/> int main (void) <br/>{< br/> int ncases; <br/> CIN> ncases; <br/> while (ncases --) <br/>{< br/> input (); <br/> Kruskal (); <br/> If (ncases! = 0) <br/> cout <Endl; <br/>}< br/> return 0; <br/>}< br/>