#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <set>
#include <unordered_map>
#include <cmath>
#include <map>
#include <cctype>
#include <cstdlib>
#include <deque>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int MN = 65005;
const int MAXN = 1000010;
const int INF = 0x3f3f3f3f;
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) ((x)&(-x))
int n;
struct node {
double x, y;
};
node ver[MAXN];
bool vis[MAXN];
double d[MAXN];
double cal(int a, int b) {
return sqrt((ver[a].x - ver[b].x) * (ver[a].x - ver[b].x) + (ver[a].y - ver[b].y) * (ver[a].y - ver[b].y));
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%lf %lf", &ver[i].x, &ver[i].y);
d[i] = INF;
}
d[1] = 0;
int pos;
double ans = 0;
for (int i = 1; i <= n; i++) {
double minn = INF;
for (int j = 1; j <= n; j++) {
if (!vis[j] && minn > d[j]) {
minn = d[j], pos = j;
}
}
if (minn == INF)
break;
ans += minn;
vis[pos] = true;
for (int j = 1; j <= n; j++) {
double t = cal(pos, j);
if (t < d[j]) {
d[j] = t;
}
}
}
printf("%.2lf", ans);
return 0;
}
P1265 公路修建(Prim)
最新推荐文章于 2024-07-10 11:04:17 发布