0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2025-01-11 16:31:58 +00:00

P1265 公路修建

R41298695
This commit is contained in:
Baoshuo Ren 2020-11-05 14:59:22 +08:00 committed by Baoshuo Ren
parent 14ccb6a3bc
commit d2b9aada55
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

47
problem/P1265/P1265.cpp Normal file
View File

@ -0,0 +1,47 @@
#include <bits/stdc++.h>
using namespace std;
struct point {
long long x, y;
};
int n, m;
bool v[5005];
long long d[5005];
point city[5005];
void prim() {
memset(d, 0x3f, sizeof(d));
memset(v, 0x00, sizeof(v));
d[1] = 0;
for (int i = 1; i <= n - 1; i++) {
int x = 0;
for (int j = 1; j <= n; j++) {
if (!v[j] && (x == 0 || d[j] < d[x])) {
x = j;
}
}
v[x] = 1;
for (int y = 1; y <= n; y++) {
if (!v[y]) {
d[y] = min(d[y], (city[x].x - city[y].x) * (city[x].x - city[y].x) + (city[x].y - city[y].y) * (city[x].y - city[y].y));
}
}
}
return;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> city[i].x >> city[i].y;
}
prim();
double ans = 0.00;
for (int i = 1; i <= n; i++) {
ans += sqrt((double)(d[i]));
}
cout << fixed << setprecision(2) << ans << endl;
return 0;
}