Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <cmath>
- using namespace std;
- #define mp make_pair
- vector<pair<int, int>> point;
- double dist(int i1, int i2) {
- auto p1 = point[i1];
- auto p2 = point[i2];
- return sqrt((p1.first - p2.first)*(p1.first - p2.first) + (p1.second - p2.second)*(p1.second - p2.second));
- }
- vector<double> dst;
- int main() {
- int n;
- cin >> n;
- dst.resize(n, 1e9);
- for (int i = 0; i < n; ++i) {
- int x, y;
- cin >> x >> y;
- point.emplace_back(x, y);
- }
- vector<bool> used(n,false);
- dst[0] = 0;
- for (;;) {
- int v = -1;
- for (int i = 0; i < n; ++i) {
- if (!used[i] && dst[i] < 1e9 && (v==-1 || dst[v] > dst[i])) {
- v = i;
- }
- }
- if (v==-1) break;
- used[v] = true;
- for (int i = 0; i < n; ++i) {
- if (!used[i]) {
- dst[i] = min(dst[i], dist(v,i));
- }
- }
- }
- double res =0;
- for(int i=0;i<n;++i) {
- res += dst[i];
- }
- printf("%.10f",res);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement