/* Name: hdu1863畅通工程 Author: Try86 Date: 10/04/12 12:43 Description: 最小生成树(kruskal) */#include#include using namespace std;const int M = 5050;int p[M], sum; //sum统计顶点个数 struct edge { int a; int b; int w;}e[M];int cmp(const void *a, const void *b) { return (*(edge *)a).w - (*(edge *)b).w;} void init(int vs) { for (int i=1; i<=vs; ++i) p[i] = i; return ;}int find(int v) { if (p[v] != v) p[v] = find(p[v]); return p[v];}int join(edge e) { int x, y; x = find(e.a); y = find(e.b); if (x != y) { ++sum; p[x] = y; return e.w; } return 0;}int kruskal(int es, int vs) { int ans = 0; init(vs); qsort(e, es, sizeof(edge), cmp); for (int i=0; i