#include #include #include #include #include #include using namespace std; const int MAXN = 1e6 + 5; typedef long long LL; struct edge { int v, u, cost; bool operator <(const edge &a) const { return cost < a.cost; } } es[MAXN]; struct o { int v, cost; o() {} o(int v, int cost):v(v), cost(cost) {} }; int par[MAXN], ranks[MAXN]; int sum[MAXN]; bool vis[MAXN]; int n, m; double minres; vectorG[MAXN]; void init(int sizes) {//初始化 for(int i = 0; i <= sizes; i ++) { par[i] = i; ranks[i] = 1; G[i].clear(); } } int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); } bool same(int x,int y) { return find(x) == find(y); } void unite(int x,int y) {//连接 x = find(x); y = find(y); if(x == y)return ; if(ranks[x] > ranks[y]) { par[y] = x; } else { par[x] = y; if(ranks[x] == ranks[y]) ranks[x] ++; } } LL kruskal() {//最小生成树算法 sort(es,es + m); init(n); LL ret = 0; for(int i=0; i