Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <algorithm>
using namespace std;

const int MAXV = 10001;
const int MAXE =  MAXV * (MAXV);
const int INF = 0x3f3f3f3f;
typedef long long LL;
typedef pair<int, int> P; // 坐标点
P p[MAXV];
//int cost[MAXV][MAXV];
//int mincost[MAXV];
//bool visited[MAXV];
int N, M;
int V, E;
struct Edge {
	int from, to;
	double cost;
	Edge(int _from=0, int _to=0, double _cost = 0.0) :from(_from), to(_to), cost(_cost){}
};
Edge edge[MAXE];
int father[MAXV];
bool cmp(const Edge& a, const Edge& b) {
	return a.cost > b.cost;
}
void Init(int n) {
	for (int i = 0; i < n; ++i) {
		father[i] = i;
	}
}
int Find(int x) {
	if (father[x] == x)
		return x;
	else
		return father[x] = Find(father[x]);
}
void Unite(int x, int y) {
	x = Find(x);
	y = Find(y);
	if (x == y)
		return;
	else
		father[y] = x;
}
bool same(int x, int y) {
	return Find(x) == Find(y);
}
double Kruskal() {
	Init(MAXV);
	sort(edge, edge + E, cmp);
	double res = 0;
	int cnt = 0;
	for (int i = 0; i < E; ++i) {
		Edge e = edge[i];
		if (!same(e.from, e.to)) {
			Unite(e.from, e.to);
			cnt++;
		}
		else {
			res += e.cost;
		}
		//if (cnt == V - 1)
		//	break;
	}
	//if (cnt < V - 1)
	//	return -1;
	//else
		return res;
}
//struct Edge {
//	int to, cost;
//	Edge(int _to = 0, int _cost = 0) :to(_to), cost(_cost){}
//};
//vector<Edge> edge[MAXE];
//int Prim() {
//	fill(mincost, mincost + MAXV, 0);
//	fill(visited, visited + MAXV, false);
//	mincost[0] = 0;
//	int res = 0;
//	int cnt = 0;
//	priority_queue<P> que;
//	que.push(P(0, 0));
//	while (!que.empty()) {
//		P p = que.top(); que.pop();
//		int v = p.second;
//		if (visited[v] || mincost[v] > p.first)
//			continue;
//		res += mincost[v];
//		visited[v] = true;
//		cnt++;
//		for (int i = 0; i < edge[v].size(); ++i) {
//			Edge e = edge[v][i];
//			if (mincost[e.to] < e.cost) {
//				mincost[e.to] = e.cost;
//				que.push(P(mincost[e.to], e.to));
//			}
//		}
//	}
//	if (cnt < V)
//		return -1;
//	else if (cnt)
//		return res;
//}
void solve() {
	double res = Kruskal();
	printf("%.3f\n", res);
}
int main(int argc, char const *argv[])
{
	//std::ios::sync_with_stdio(false);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	while (scanf("%d%d", &N, &M) != EOF) {
		V = N; E = 0;
		memset(edge, 0, sizeof(edge));
		int x, y;
		for (int i = 0; i < N; ++i) {
			scanf("%d%d", &x, &y);
			p[i].first = x;
			p[i].second = y;
		}
		int from, to, cost;
		for (int i = 0; i < M; ++i) {
			scanf("%d%d", &from, &to);
			--from; --to;
			int dx = abs(p[from].first - p[to].first);
			int dy = abs(p[from].second - p[to].second);
			double dist = sqrt(dx * dx + dy * dy);
			edge[E++] = Edge(from, to, dist);
		}
		solve();
	}
	//system("pause");
	return 0;
}




Compiler output:
a.cc: In function 'int main(int, const char**)':
a.cc:121:17: error: 'memset' was not declared in this scope
  121 |                 memset(edge, 0, sizeof(edge));
      |                 ^~~~~~
a.cc:7:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    6 | #include <algorithm>
  +++ |+#include <cstring>
    7 | using namespace std;
a.cc:134:39: error: 'sqrt' was not declared in this scope
  134 |                         double dist = sqrt(dx * dx + dy * dy);
      |                                       ^~~~