Links: http://poj.org/problem?id=1861
Minimum spanning tree bare topic, output spanning tree's longest edge, number of nodes, node coordinates. In addition OJ the sample output is wrong, the minimum spanning tree of 4 points can be 4 sides.
is mainly familiar with handwriting Kruskal
#include <cstring> #include <string> #include <fstream> #include <iostream> #include < iomanip> #include <cstdio> #include <cctype> #include <algorithm> #include <queue> #include <map> #include <set> #include <vector> #include <stack> #include <ctime> #include < cstdlib> #include <functional> #include <cmath>using namespace std; #define PI ACOs ( -1.0) #define MAXN 20010#define EPS 1e-7#define INF 0x7fffffff#define seed 131#define ll long long#define ull unsigned ll#define lson l,m,rt& Lt;<1#define rson m+1,r,rt<<1|1struct node{int U,v,dis;} Edge[maxn];int father[1010],point[1010][2];int N,m,ans,sum;bool CMP (node X,node y) {return x.dis<y.dis;} int find (int x) {int t = x; while (T!=father[t]) {t = father[t]; } int k = x; while (k!=t) {int temp = father[k]; Father[k] = t; K = temp; } return t;} void Kruskal () {int i,j=0; for (i=1;i<=n;i++) father[i] = i; for (i=0;i<m;i++) {int a = find (EDGE[I].U); int b = Find (EDGE[I].V); if (a!=b) {Father[a] = b; Point[j][0] = edge[i].u; POINT[J][1] = EDGE[I].V; Sum+=edge[i].dis; ans = Edge[i].dis; j + +; if (j>=n-1) break; }}}int Main () {int i,j; while (scanf ("%d%d", &n,&m)!=eof) {sum = 0; for (i=0;i<m;i++) {scanf ("%d%d%d", &edge[i].u,&edge[i].v,&edge[i].dis); } sort (edge,edge+m,cmp); Kruskal (); printf ("%d\n%d\n", ans,n-1); for (i=0;i<n-1;i++) {printf ("%d%d\n", point[i][0],point[i][1]); }} return 0;}