Problem:
Problem C:
Save your cats
Nicholas Y. Alford was a cat lover. He had a garden in a village and kept many cats in his garden. The cats were so cute that people in the village also loved them.
One day, an evil witch visited the village. She envied the cats for being loved by everyone. She drove magical piles in his garden and enclosed the cats with magical fences running between the piles. She said “Your cats are shut away in the fences until they become ugly old cats.” like a curse and went away.
Nicholas tried to break the fences with a hummer, but the fences are impregnable against his effort. He went to a church and asked a priest help. The priest looked for how to destroy the magical fences in books and found they could be destroyed by holy water. The Required amount of the holy water to destroy a fence was proportional to the length of the fence. The holy water was, however, fairly expensive. So he decided to buy exactly the minimum amount of the holy water required to save all his cats. How much holy water would be required?
Input
The input has the following format:
N M
x
1
y
1
.
.
.
x
N
y
N
p
1
q
1
.
.
.
p
M
q
M
The first line of the input contains two integers
N
(2 ≤
N
≤ 10000) and
M
(1 ≤
M
).
N
indicates the number of magical piles and
M
indicates the number of magical fences. The following
N
lines describe the coordinates of the piles. Each line contains two integers
x
i
and
y
i
(-10000 ≤
x
i
,
y
i
≤ 10000). The following
M
lines describe the both ends of the fences. Each line contains two integers
p
j
and
q
j
(1 ≤
p
j
,
q
j
≤
N
). It indicates a fence runs between the
p
j
-th pile and the
q
j
-th pile.
You can assume the following:
No Piles have the same coordinates.
A pile doesn’t lie on the middle of fence.
No Fences cross each other.
There is at least one cat in each enclosed area.
It is impossible to destroy a fence partially.
A unit of holy water is required to destroy a unit length of magical fence.
Output
Output a line containing the minimum amount of the holy water required to save all his cats. Your program may output an arbitrary number of digits after the decimal point. However, the absolute error should be 0.001 or less.
Sample Input 1
3 3
0 0
3 0
0 4
1 2
2 3
3 1
Output for the Sample Input 1
3.000
Sample Input 2
4 3
0 0
-100 0
100 0
0 100
1 2
1 3
1 4
Output for the Sample Input 2
0.000
Sample Input 3
6 7
2 0
6 0
8 2
6 3
0 5
1 7
1 2
2 3
3 4
4 1
5 1
5 4
5 6
Output for the Sample Input 3
7.236
Sample Input 4
6 6
0 0
0 1
1 0
30 0
0 40
30 40
1 2
2 3
3 1
4 5
5 6
6 4
Output for the Sample Input 4
31.000

Submitted solutions:

code_snippet: #include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;
const int maxn=1e4+5;
typedef long long LL;
struct Point
{
    int x;
    int y;
};

struct  edge
{
    int to;
    double cost;
};
Point a[maxn];
vector<edge> g[maxn];
bool used[maxn];
int n,m;
double maxcost[maxn];
double cal_distance(Point a,Point b)
{
  return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double  prim(int p)
{
  double ans=0.0;
  maxcost[p]=0.0;
  while(1)
  {
      int v=-1;
      for(int u=1;u<=n;u++)
        if(!used[u]&&(v==-1||maxcost[u]>maxcost[v]))
        v=u;
      if(v==-1||maxcost[v]==-1)
        break;
      used[v]=1;
      ans+=maxcost[v];
     for(int i=0;i<g[v].size();i++)
     {
         edge &e=g[v][i];
         maxcost[e.to]=max(maxcost[e.to],e.cost);
     }
  }
  return ans;
}
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        for(int i=1;i<=n;i++)
            g[i].clear();
        for(int i=1;i<=n;i++)
            scanf("%d%d",&a[i].x,&a[i].y);
        int p1,p2;
        double sum=0;
        for(int i=1;i<=m;i++)
        {
            scanf("%d%d",&p1,&p2);
            double tmp=cal_distance(a[p1],a[p2]);
            g[p1].push_back((edge){p2,tmp});
            g[p2].push_back((edge){p1,tmp});
            sum+=tmp;
        }
//        for(int i=1;i<=n;cout<<endl,i++)
//            for(int j=1;j<=n;j++)
//             cout<<cost[i][j]<<" ";
//        cout<<sum<<endl;
          memset(used,0,sizeof(used));
          for(int i=0;i<=n;i++)
                maxcost[i]=-1;
          double ans=0.0;
            for(int u=1;u<=n;u++)
               if(!used[u])
                  ans+=prim(u);
          ans=sum-ans;
         printf("%.3f\n",ans);
    }
    return 0;
}
accuracy: 1
time_ms: 220
memory_kb: 5484
final_rank: 18

code_snippet: #include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

struct UnionFind{
  vector<int> par;
  UnionFind(int N):par(N){
    REP(i,N)par[i]=i;
  }
  int root(int x){
    if(par[x]==x)return x;
    return par[x]=root(par[x]);
  }
  void unite(int x,int y){
    int rx=root(x);
    int ry=root(y);
    if(rx==ry)return;
    par[rx]=ry;
  }
};

int main(){
  int N,M;
  cin>>N>>M;
  vector<pair<lint,lint> > piles;
  vector<pair<int,int> > fence;
  REP(i,N){
    int x,y;
    cin>>x>>y;
    piles.push_back(make_pair(x,y));
  }
  REP(i,M){
    int p,q;
    cin>>p>>q;
    p--;q--; // 0index
    fence.push_back(make_pair(p,q));
  }
  // 各フェンスを切るのにかかるコスト
  vector<pair<double,int> > cost;
  REP(i,M){
    auto [x1,y1] = piles[fence[i].first];
    auto [x2,y2] = piles[fence[i].second];
    double c = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); 
    // 降順ソートが面倒なので負数にしておく
    cost.push_back(make_pair(-c,i));
  }
  double ans = 0;
  UnionFind tree(N);
  // コストの高いフェンスから閉路ができないように貪欲につないでいく
  sort(ALL(cost)); // vector<pair>をソートすると第一要素の昇順ソートになる
  for(auto ci : cost){
    auto [c, i] = ci;
    auto [p,q] = fence[i];
    // 閉路が形成されるならつながない = 切るフェンスとして答えに加える
    if(tree.root(p)==tree.root(q)){
      ans += -c;
    }else{
      tree.unite(p,q);
    }
  }
  //固定小数点
  cout<<fixed;
  //桁数固定
  cout<<setprecision(10);
  cout<<ans<<endl;

  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4164
final_rank: 8

code_snippet: #include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

struct UnionFind{
  vector<int> par;
  UnionFind(int N):par(N){
    REP(i,N)par[i]=i;
  }
  int root(int x){
    if(par[x]==x)return x;
    return par[x]=root(par[x]);
  }
  void unite(int x,int y){
    int rx=root(x);
    int ry=root(y);
    if(rx==ry)return;
    par[rx]=ry;
  }
};

int main(){
  int N,M;
  cin>>N>>M;
  vector<pair<lint,lint> > piles;
  vector<pair<int,int> > fence;
  REP(i,N){
    int x,y;
    cin>>x>>y;
    piles.push_back(make_pair(x,y));
  }
  REP(i,M){
    int p,q;
    cin>>p>>q;
    p--;q--; // 0index
    fence.push_back(make_pair(p,q));
  }
  // 各フェンスを切るのにかかるコスト
  vector<pair<double,int> > cost;
  REP(i,M){
    auto [x1,y1] = piles[fence[i].first];
    auto [x2,y2] = piles[fence[i].second];
    double c = -sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); // 降順ソートが面倒なので負数にしておく
    cost.push_back(make_pair(c,i));
  }
  double ans = 0;
  UnionFind tree(N);
  // コストの高いフェンスから貪欲に繋いでいく
  sort(ALL(cost));
  for(auto ci : cost){
    auto [c, i] = ci;
    auto [p,q] = fence[i];
    // ループが形成されるならつながない
    if(tree.root(p)==tree.root(q)){
      ans += -c;
    }else{
      tree.unite(p,q);
    }
  }
  //固定小数点
  cout<<fixed;
  //桁数固定
  cout<<setprecision(10);
  cout<<ans<<endl;

  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4096
final_rank: 6

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
#include <unordered_set>
#include <functional>
using namespace std;
//using namespace atcoder;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
//void chmin(ll & a, ll b) { a = min(a, b); }
//using mint = modint998244353;
//using mint = modint1000000007;

struct UnionFind {
	vector<int> par, rank;

	UnionFind(int n = 210000) { init(n); }
	void init(int n = 210000) {
		par.resize(n);
		rank.resize(n);
		rep(i, n) par[i] = i, rank[i] = 0;
	}

	int root(int x) {
		if (par[x] == x) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x), y = root(y);
		if (x == y) return false;
		if (rank[x] < rank[y]) swap(x, y);
		if (rank[x] == rank[y]) rank[x]++;
		par[y] = x;
		return true;
	}
};

typedef pair<double, P> Edge;

int main() {
	int N, M;
	cin >> N >> M;
	vector<double> x(N), y(N);
	rep(i, N) cin >> x[i] >> y[i];
	vector<Edge> edges;
	double all = 0;
	for (int i = 0; i < M; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		double dis = sqrt((x[u] - x[v]) * (x[u] - x[v]) + (y[u] - y[v]) * (y[u] - y[v]));
		edges.push_back(Edge(dis, P(u, v)));
		all += dis;
	}

	sort(edges.rbegin(), edges.rend());
	UnionFind uf(N);
	double hosyu = 0;
	for (auto e : edges) {
		int u = e.second.first, v = e.second.second;
		if (uf.issame(u, v)) continue;
		hosyu += e.first;
		uf.merge(u, v);
	}

	cout << fixed << setprecision(10) << all - hosyu << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3956
final_rank: 4

code_snippet: #define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stdio.h>
#include <map>
#include<sstream>
#include <set>
#include <string.h>
#include <math.h>
#include <cmath>
#include <cstdio>
#include <iomanip>
using namespace std;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)

struct edge {
	int from, to; 
	double cost;
	edge() {}
	edge(int f, int t, double c):from(f),to(t),cost(c){}
	bool operator<(const edge& b)const{
		return cost > b.cost;
	}
};

int par[10009];
int ranks[10009];

void init(int n) {
	rep(i, n) {
		par[i] = i;
		ranks[i] = 0;
	}
}

int find(int x) {
	if (x == par[x]) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) return;

	if (ranks[x] < ranks[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (ranks[x] == ranks[y]) ranks[x]++;
	}
}

bool same(int x, int y) {
	return find(x) == find(y);
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<edge> e;
	vector<int> x(N), y(N);
	rep(i, N) cin >> x[i] >> y[i];

	auto calc_dist = [&](int p, int q) ->double {
		return sqrt((x[p] - x[q]) * (x[p] - x[q]) + (y[p] - y[q]) * (y[p] - y[q]));
		};

	double sum = 0;
	rep(i, M) {
		int p, q;
		cin >> p >> q;
		p--, q--;
		e.push_back(edge(p, q, calc_dist(p, q)));
		e.push_back(edge(q, p, calc_dist(q, p)));
		sum += calc_dist(p, q);
	}

	sort(e.begin(), e.end());
	init(N);
	
	double sub_sum = 0;
	rep(i, e.size()) {
		if (same(e[i].from, e[i].to)) continue;
		sub_sum += e[i].cost;
		unite(e[i].from, e[i].to);
	}

	cout << fixed <<setprecision(12) <<sum - sub_sum << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4200
final_rank: 10

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

struct dsu {
  public:
    dsu() : _n(0) {}
    dsu(int n) : _n(n), parent_or_size(n, -1) {}

    int merge(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y) return x;
        if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }

    bool same(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(int a) {
        assert(0 <= a && a < _n);
        if (parent_or_size[a] < 0) return a;
        return parent_or_size[a] = leader(parent_or_size[a]);
    }

    int size(int a) {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    std::vector<std::vector<int>> groups() {
        std::vector<int> leader_buf(_n), group_size(_n);
        for (int i = 0; i < _n; i++) {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        std::vector<std::vector<int>> result(_n);
        for (int i = 0; i < _n; i++) {
            result[i].reserve(group_size[i]);
        }
        for (int i = 0; i < _n; i++) {
            result[leader_buf[i]].push_back(i);
        }
        result.erase(
            std::remove_if(result.begin(), result.end(),
                           [&](const std::vector<int>& v) { return v.empty(); }),
            result.end());
        return result;
    }

  private:
    int _n;
    // root node: -1 * component size
    // otherwise: parent
    std::vector<int> parent_or_size;
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<double> X(N), Y(N);
    vector<pair<double,pair<int,int>>> V(M);
    rep(i,0,N) cin >> X[i] >> Y[i];
    double ANS = 0.0;
    rep(i,0,M) {
        int A, B;
        cin >> A >> B;
        A--, B--;
        double D = sqrt((X[A]-X[B])*(X[A]-X[B])+(Y[A]-Y[B])*(Y[A]-Y[B]));
        ANS += D;
        V[i] = {D,(pair<int,int>){A,B}};
    }
    sort(ALL(V));
    reverse(ALL(V));
    dsu UF(N);
    rep(i,0,M) {
        if (!UF.same(V[i].second.first, V[i].second.second)) ANS -= V[i].first;
        UF.merge(V[i].second.first, V[i].second.second);
    }
    print(ANS);
}
accuracy: 1
time_ms: 10
memory_kb: 3892
final_rank: 3

code_snippet: #include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAX_N = 10000;

int par[MAX_N]; 
int rank_uf[MAX_N]; 

void init_union_find(int);
int find(int);
void unite(int, int);
bool same(int, int);

struct edge {double u, v, cost ; } ;

bool comp(const edge& e1, const edge &e2) {
    return e1.cost < e2.cost;
}

vector<edge> es;
int V;

double kruskal();

int N, M, xi, yi, pi, qi;
double x[MAX_N], y[MAX_N];

int main() {
    cin >> N >> M;
    V = N;
    for (int i = 0; i < V; i++) {
        cin >> xi >> yi;
        x[i] = xi; y[i] = yi;
    }
    double ans = 0;
    for (int i = 0; i < M; i++) {
        cin >> pi >> qi;
        pi--; qi--;
        es.push_back((edge){(double)pi, (double)qi, -sqrt((x[pi] - x[qi]) * (x[pi] - x[qi]) + (y[pi] - y[qi]) * (y[pi] - y[qi]))});
        ans += sqrt((x[pi] - x[qi]) * (x[pi] - x[qi]) + (y[pi] - y[qi]) * (y[pi] - y[qi]));
    }
    printf("%.3f\n", ans + kruskal());
    return 0;
}

void init_union_find(int n) {
    for (int i = 0; i < n; i++) {
        par[i] = i;
        rank_uf[i] = 0;
    }
}

int find(int x) {
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
        return;
    if (rank_uf[x] < rank_uf[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (rank_uf[x] == rank_uf[y])
            rank_uf[x]++;
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}

double kruskal() {
    sort(es.begin(), es.end(), comp);
    init_union_find(V);
    double res = 0;
    for (int i = 0; i < es.size(); i++) {
        edge e = es[i];
        if (!same(e.u, e.v)) {
            unite(e.u, e.v);
            res += e.cost;
        }
    }
    return res;
}
accuracy: 1
time_ms: 10
memory_kb: 4224
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;

// 辺情報を表す構造体
struct edge {
    int from;   // 辺の始点
    int to;     // 辺の終点
    double leng;   // 辺の重み
};

// 構造体 edge の比較関数
bool comp(const edge &e, const edge &f) {
    return e.leng > f.leng;
}

struct UnionFind{
    vector<int> par;    //(例) par[3] = 2 : 3の親が2
    vector<int> rank;   //根の深さ
    vector<int> siz;    //根付き木に含まれる頂点数
    vector<int> min_node; //連結成分の最小値
    //ｎ要素で最初は全てが根であるとして初期化
    //子：親のID、親：負のサイズ（-1）と仮定する
    UnionFind(int n) : par(n),rank(n),siz(n),min_node(n){
        for(int i=0; i<n; i++){
            par[i] = -1;
            rank[i] = 0;
            siz[i] = 1;
            min_node[i] = i;// 初期状態では min_node は自分自身
        } 
    }
    //木の根を求める …データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    int root(int x){
        if(par[x] < 0){ //根？
            return x;
        }else{
            return par[x] = root(par[x]);   //経路圧縮
        }
    }
    //ｘとｙが同じ集合に属するか否か
    bool same(int x,int y){
        return (root(x) == root(y));
    }
    bool unite(int x,int y){
        x = root(x);
        y = root(y);
        if(x == y ) return false;
        if(rank[x] < rank[y]){
          swap(x,y);
        }
        par[y] = x;
        if(rank[x] == rank[y]) rank[x]++;
        siz[x] += siz[y];
        // min_node の更新
        min_node[x] = min(min_node[x], min_node[y]);
        return true;
    }
    int size(int x){
        return siz[root(x)]; // x を含む根付き木のサイズ(要素 x の属する根付き木に含まれる頂点数)
    }
    
    //x を含む根付き木の中での頂点番号の最小値
    int get_min_node(int x) {
        return min_node[root(x)];
    }
};

double dis(int x1, int y1,int x2, int y2){
  double meter = (double)sqrt((double)(x1-x2)*(x1-x2)+(double)((y1-y2)*(y1-y2)));
  return meter;
}

int main() {
	int n,m;
  cin >> n >> m;
  vector<edge> graphedge(m);
  vector<int> x(n),y(n),p(m),q(m);
  for(int i=0;i<n;i++){
    cin >> x[i] >> y[i];
  }
  for(int i=0;i<m;i++){
    cin >> p[i] >> q[i];
    p[i]--;q[i]--;
  }

  double sum_weight=0;
  for(int i=0;i<m;i++){
    double w=dis(x[p[i]],y[p[i]],x[q[i]],y[q[i]]);
    graphedge[i]={p[i],q[i],w};
    sum_weight+=w;
  }
  sort(graphedge.begin(),graphedge.end(),comp);
  UnionFind uf(n);

  for(int i=0;i<m;i++){
    auto [u,v,w] = graphedge[i];
    if(uf.same(u,v)) continue;
    uf.unite(u,v);
    sum_weight-=w;
  }
  printf("%.10lf\n",sum_weight);
  return 0;

}
accuracy: 1
time_ms: 10
memory_kb: 4168
final_rank: 9

code_snippet: #include <algorithm>
#include <cctype>
#include <climits>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long double ll;
const ll INF = 10000000;

class UFT{
private:
  int par[100000];
  int ranks[100000];
  int group;

  void init(int n){
    for(int i = 0; i < n; i++){
      par[i] = i;
      ranks[i] = 0;
    }
    group = n;
  }
public:
  UFT(int N){
    init(N);
  }

  int find(int x){
    if(par[x] == x) return x;
    else return find(par[x]);
  }

  void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y)return;

    if(ranks[x] < ranks[y]) par[x] = y;
    else if(ranks[x] == ranks[y]){
      par[y] = x;
      ranks[x]++;
    }
    else par[y] = x;
    group--;
  }

  bool same(int x, int y){
    return find(x) == find(y);
  }

  int count_group(){
    return group;
  }
};
//Graph
struct edge{
  int from, to; ll cost;

  edge(const int f, const int t, const ll c=INF){
    from = f; to = t; cost = c;
  }

  bool operator<(const edge& e2){
    return cost < e2.cost;
  }
};

class Graph{
private:
  vector<vector<edge>>neighbors;
  vector<ll>shortest;
  vector<int>prev;
  //this is for warshall froid.
  vector<vector<ll>>distances;
  int V;
  int E;

  // for priority_queue of edge
  struct comp{
  bool operator()(struct edge a, struct edge b){
    return (a.cost > b.cost);
  }
};

public:
  Graph(){}
  Graph(const int n){
    V = n; E = 0;
    neighbors = vector<vector<edge>>(V);
  };

  void add_edge(const int f, const int t, const ll c=INT_MAX){
    edge e(f, t, c);
    neighbors[f].push_back(e);
    E++;
  }

  //Dijkstra
  void dijkstra(const int s){
    typedef pair<ll, int> P;
    shortest = vector<ll>(V, INF);
    prev = vector<int>(V, -1);
    priority_queue<P, vector<P>, greater<P>>pque;
    shortest[s] = 0;
    pque.push(P(0, s));

    while(!pque.empty()){
      P p = pque.top(); pque.pop();
      if(shortest[p.second] < p.first)continue;
      for(int i = 0; i < neighbors[p.second].size(); i++){
        edge e = neighbors[p.second][i];
        if(shortest[e.to] > shortest[p.second] + e.cost){
          shortest[e.to] = shortest[p.second] + e.cost;
          prev[e.to] = p.second;
          pque.push(P(shortest[e.to], e.to));
        }
      }
    } 
  }

  //Bellman-Ford algorithm
  void Bellman_Ford(const int s){
    shortest = vector<ll>(V, INF);
    prev = vector<int>(V, -1);
    shortest[s] = 0;
    while(true){
      bool updated = false;
      for(int i = 0; i < V; i++){
        for(int j = 0; j < neighbors[i].size(); j++){
          edge e = neighbors[i][j];
          if(shortest[i] != INF && shortest[i] + e.cost < shortest[e.to]){
            shortest[e.to] = shortest[i] + e.cost;
            prev[e.to] = i;
            updated = true;
          }
        }
      }

      if(!updated)break;
    }
  }

  //Warshall_froid
  void warshall_froid(){
    distances = vector<vector<ll>>(V, vector<ll>(V, INF));
    for(int i = 0; i < V; i++){
      distances[i][i] = 0;
      for(int j = 0; j < neighbors[i].size(); j++){
        edge e = neighbors[i][j];
        distances[i][e.to] = e.cost;
      }
    }

    for(int k = 0; k < V; k++){
      for(int i = 0; i < V; i++){{
        for(int j = 0; j < V; j++){
          if(distances[i][k] != INF && distances[k][j] != INF) distances[i][j] = min(distances[i][j], distances[i][k] + distances[k][j]);
        }
      }
      }
    }
  }

  //prim. It works for connected graphs.
  ll prim(){
    ll minimum = 0;
    vector<bool>used(V, false);
    prev = vector<int>(V, -1);
    priority_queue<edge, vector<edge>, comp>pque;
    pque.push(edge(0, 0, 0));

    while(!pque.empty()){
      edge e = pque.top(); pque.pop();
      if(used[e.to]) continue;
      minimum += e.cost;
      used[e.to] = true;
      prev[e.to] = e.from;
      for(int i = 0; i < neighbors[e.to].size(); i++){
        edge next = neighbors[e.to][i];
        if(!used[next.to]){
          pque.push(next);
        }
      }
    }
    return minimum;
  }

  //kruskal It works for any type of graphs. However, it's difficult to restor paths. If you need the paths that makes forest, you should declare some vector to track them.
  //However, it messes the code up, so do declare flexibly if you want. 
  ll kruskal(){
    vector<edge> edges;
    for(int i = 0; i < V; i++){
      for(int j = 0; j < neighbors[i].size(); j++){
        edges.push_back(neighbors[i][j]);
      }
    }
    sort(edges.rbegin(), edges.rend());

    ll minimum = 0;
    UFT tree(V);

    for(int i = 0; i < E; i++){
      edge e = edges[i];
      if(!tree.same(e.from, e.to)){
        tree.unite(e.from, e.to);
        minimum += e.cost;
      }
    }

    return minimum;
  }

  //find negative loop
  bool find_negative_loop(){
    shortest = vector<ll>(V, 0);
    for(int i = 0; i < V; i++){
      for(int j = 0; j < V; j++){
        for(int k = 0; k < neighbors[j].size(); k++){
          edge e = neighbors[j][k];
          if(shortest[j] + e.cost < shortest[e.to]){
            shortest[e.to] = shortest[j] + e.cost;
            if(i == V-1)return true;
          }
        }
      }
    }
    return false;
  }

  //get the shortest path from s to g
  //make sure it is done after algorithm
  ll get_value(const int g){
    return shortest[g];
  }
  ll get_value(const int s, const int g){
    return distances[s][g];
  }


  //get the shortest path route from s to g
  //make sure it is done after algorithm
  vector<int> get_route(const int s, const int g){
    vector<int>routes;
    if(get_value(g) == INF)return routes;

    for(int t = g; prev[t] != -1; t = prev[t])routes.push_back(t);
    routes.push_back(s);
    reverse(routes.begin(), routes.end());
    return routes;
  }
};

struct Point{int x, y;};
ll caluculate(Point& p1, Point& p2){
    return sqrt(pow(p1.x-p2.x, 2)+pow(p1.y-p2.y, 2));
}
int main(){
  int N, M; scanf("%d%d", &N, &M);
  Graph G(N);

  vector<Point>coordinates(N);
  for(int i = 0; i < N; i++){
    Point p; scanf("%d%d", &p.x, &p.y);
    coordinates[i] = p;
  }

  ll total = 0;
  for(int i = 0; i < M; i++){
    int f, s; scanf("%d%d", &f, &s);
    ll d = caluculate(coordinates[f-1], coordinates[s-1]);
    G.add_edge(f-1, s-1, d); 
    G.add_edge(s-1, f-1, d); 
    total += d;
  }

  cout << fixed << setprecision(4) << total - G.kruskal();
}
accuracy: 1
time_ms: 10
memory_kb: 8256
final_rank: 17

code_snippet: #include<iostream>
#include<vector>
#include<stdio.h>
#include<algorithm> 
#include<math.h>
using namespace std;
int n,m,k;
vector<pair<int,int> >point;
double ans=0;
struct node{
	double dis;
	int u,v;
	bool operator < (const node p)const{
		return dis>p.dis;
	} 
}; 
vector<node> vec;
vector<int> par;
int find(int x){
	return x==par[x] ? x:par[x]=find(par[x]);
}
bool unite(int x,int y){
	x=find(x);y=find(y);
	if(x==y)return false;
	par[x]=y;return true; 
}
void func(){
	sort(vec.begin(),vec.end());
	for(int i=0;i<m;i++){
		if(unite(vec[i].u,vec[i].v)){
			ans+=vec[i].dis;
		}
	}
}
int main(){
	cin>>n>>m;
	point.resize(n+1);vec.resize(m);par.resize(n+1);
	for(int i=1;i<=n;i++){
		par[i]=i;
		cin>>point[i].first>>point[i].second;
	} 
	int label=0;
	double sum=0;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		double dis=sqrt((point[a].first-point[b].first)*(point[a].first-point[b].first)+(point[a].second-point[b].second)*(point[a].second-point[b].second));
		sum+=dis;
		vec[label++]={dis,a,b};
	}
	func();
	double final=sum-ans;
	printf("%.3f\n",final);
}
accuracy: 1
time_ms: 10
memory_kb: 3600
final_rank: 1

code_snippet: // #include<cstdio>
#include<cmath>
#include<limits>
#include<iostream>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<ctime>
#include<queue>
#include<vector>
#include<iomanip>
using namespace std;
const double INF = numeric_limits<double>::max() /*INT_MAX*/ ;
#define For(x, n) for(int x = 0, fend = n; x < fend; x++)

typedef pair<double, int> P;
const int MAX_N = 10000;
const int MAX_M = 30000;
const int MAX_XY = 10000;

struct edge { int to; double cost; };
vector<edge> G[MAX_N];

bool used[MAX_N];

int N, M;
double x[MAX_N],y[MAX_N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    double all = 0, subtracted = 0;
    cin >> N >> M;
    
    For(i, N) {
        cin >> x[i] >> y[i];
    }
    For(i, M) {
        int p, q;
        edge e1,e2;
        cin >> p >> q; p--; q--;
        e1.cost = e2.cost = pow((x[p]-x[q]) * (x[p] - x[q]) + (y[p] - y[q]) * (y[p] - y[q]), 0.5);
        all += e1.cost;
        e1.to = q; e2.to = p;
        G[p].push_back(e1); G[q].push_back(e2);
    }
    For(i, N) {
        used[i] = false;
    }
    priority_queue<P> que;
    int iv = 0;
    while (iv < N) {
        while (used[iv])iv++;
        que.push(P(0, iv));
        while (!que.empty()) {
            P p = que.top(); que.pop();
            int v = p.second;
            if (used[v])continue;
            used[v] = true;
            subtracted += p.first;

            For(i, G[v].size()) {
                edge e = G[v][i];
                if (!used[e.to]) {
                    que.push(P(e.cost, e.to));
                }
            }
        }
    }
    cout << fixed << setprecision(3)<< all - subtracted << endl;

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 5356
final_rank: 15

code_snippet: #include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#define maxn 11000
#define oo 0xfffffff
using namespace std;
int father[maxn], n, m;
struct node {
  int u, v;
  double w;
} s[maxn * 100];
struct point {
  int x, y;
} a[maxn];
double Len(int p, int q) {
  double d = sqrt((a[p].x - a[q].x) * (a[p].x - a[q].x) +
                  (a[p].y - a[q].y) * (a[p].y - a[q].y));
  return d;
}
int Find(int x) {
  while (x != father[x])
    x = father[x];
  return x;
}
int cmp(node p, node q) { return p.w > q.w; }
double solve() {
  double ans = 0;
  for (int i = 0; i < m; i++) {
    int ru = Find(s[i].u);
    int rv = Find(s[i].v);
    if (ru != rv) {
      father[ru] = rv;
      ans += s[i].w;
    }
  }
  return ans;
}
int main() {
  int u, v;
  while (scanf("%d %d", &n, &m) != EOF) {
    double sum = 0;
    for (int i = 1; i <= n; i++)
      scanf("%d %d", &a[i].x, &a[i].y);
    for (int i = 1; i <= n; i++)
      father[i] = i;
    for (int i = 0; i < m; i++) {
      scanf("%d %d", &u, &v);
      s[i].u = u;
      s[i].v = v;
      s[i].w = Len(u, v);
      sum += s[i].w;
    }
    sort(s, s + m, cmp);
    double l = solve();
    printf("%.3f\n", sum - l);
  }
  return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3840
final_rank: 13

code_snippet: #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
const int INF = (1 << 25);
const int MAX = 10001;
int N, M;
double ans;
struct Pile {
  int x, y;
  Pile() {}
  Pile(int x, int y) : x(x), y(y) {}
};
struct State {
  int pos;
  double t;
  State() {}
  State(int pos, double t) : pos(pos), t(t) {}
  bool operator<(const State &s) const { return t < s.t; }
};
vector<int> Edge[MAX];
vector<Pile> P;
double T[MAX];
bool used[MAX];
void init() {
  fill(T, T + MAX, -1);
  fill(used, used + MAX, false);
  for (int i = 0; i < MAX; i++)
    Edge[i].clear();
  P.clear();
  ans = 0;
}
double getDis(int p, int q) {
  return sqrt((P[p].x - P[q].x) * (P[p].x - P[q].x) +
              (P[p].y - P[q].y) * (P[p].y - P[q].y));
}
void input() {
  for (int i = 0; i < N; i++) {
    Pile in;
    cin >> in.x >> in.y;
    P.push_back(in);
  }
  for (int i = 0; i < M; i++) {
    int p, q;
    cin >> p >> q;
    p--;
    q--;
    Edge[p].push_back(q);
    Edge[q].push_back(p);
    ans += getDis(p, q);
  }
}
void prim(int start) {
  priority_queue<State> Q;
  Q.push(State(start, 0));
  T[start] = 0;
  while (!Q.empty()) {
    State now = Q.top();
    Q.pop();
    if (used[now.pos])
      continue;
    used[now.pos] = true;
    ans -= now.t;
    for (int i = 0; i < (int)Edge[now.pos].size(); i++) {
      int nex = Edge[now.pos][i];
      if (T[nex] < getDis(now.pos, nex)) {
        T[nex] = getDis(now.pos, nex);
        Q.push(State(nex, getDis(now.pos, nex)));
      }
    }
  }
}
void solve() {
  for (int i = 0; i < N; i++) {
    if (!used[i])
      prim(i);
  }
  printf("%.3f\n", ans);
}
int main() {
  while (cin >> N >> M && N + M) {
    init();
    input();
    solve();
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4148
final_rank: 7

code_snippet: #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
const int INF = (1 << 25);
const int MAX = 10001;
int N, M;
double ans;
struct Pile {
  int x, y;
  Pile() {}
  Pile(int x, int y) : x(x), y(y) {}
};
struct State {
  int pos;
  double t;
  State() {}
  State(int pos, double t) : pos(pos), t(t) {}
  bool operator<(const State &s) const { return t < s.t; }
};
vector<int> Edge[MAX];
vector<Pile> P;
double T[MAX];
bool used[MAX];
void init() {
  fill(T, T + MAX, -1);
  memset(used, false, sizeof(used));
  for (int i = 0; i < MAX; i++)
    Edge[i].clear();
  P.clear();
  ans = 0;
}
double getDis(int p, int q) {
  return sqrt((P[p].x - P[q].x) * (P[p].x - P[q].x) +
              (P[p].y - P[q].y) * (P[p].y - P[q].y));
}
void input() {
  for (int i = 0; i < N; i++) {
    Pile in;
    scanf("%d %d", &in.x, &in.y);
    P.push_back(in);
  }
  for (int i = 0; i < M; i++) {
    int p, q;
    scanf("%d %d", &p, &q);
    p--;
    q--;
    Edge[p].push_back(q);
    Edge[q].push_back(p);
    ans += getDis(p, q);
  }
}
void prim(int start) {
  priority_queue<State> Q;
  Q.push(State(start, 0));
  T[start] = 0;
  while (!Q.empty()) {
    State now = Q.top();
    Q.pop();
    if (used[now.pos])
      continue;
    used[now.pos] = true;
    ans -= now.t;
    for (int i = 0; i < (int)Edge[now.pos].size(); i++) {
      int nex = Edge[now.pos][i];
      double cos = getDis(now.pos, nex);
      if (T[nex] < cos) {
        T[nex] = cos;
        Q.push(State(nex, cos));
      }
    }
  }
}
void solve() {
  for (int i = 0; i < N; i++) {
    if (!used[i])
      prim(i);
  }
  printf("%.3f\n", ans);
}
int main() {
  while (cin >> N >> M && N + M) {
    init();
    input();
    solve();
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4216
final_rank: 11

code_snippet: #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
#define N 100005
#define P pair<int, int>
#define ll long long
#define mk(a, b) make_pair(a, b)
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
int inf = 0x3f3f3f3f;
int n, m, pre[N];
double sum;
bool vis[N];
double dis[N];
struct ac {
  int v;
  double c;
};
vector<P> a(N);
vector<ac> g[N];
void init() {
  for (int i = 1; i < N; ++i) {
    pre[i] = i;
  }
}
int find(int x) {
  if (x == pre[x])
    return x;
  else
    return pre[x] = find(pre[x]);
}
void join(int x, int y) {
  int fx = find(x);
  int fy = find(y);
  if (fx == fy)
    return;
  else if (fx < fy)
    pre[fy] = fx;
  else
    pre[fx] = fy;
}
void prim(int x) {
  mem(dis, 0);
  mem(vis, false);
  for (int i = 0; i < g[x].size(); ++i) {
    ac t = g[x][i];
    dis[t.v] = t.c;
  }
  vis[x] = true;
  for (int i = 1; i < n; ++i) {
    double MAX = 0;
    int u = -1;
    for (int j = 1; j <= n; ++j) {
      if (vis[j])
        continue;
      if (dis[j] > MAX) {
        MAX = dis[j];
        u = j;
      }
    }
    if (u == -1)
      return;
    vis[u] = true;
    sum += MAX;
    for (int j = 0; j < g[u].size(); ++j) {
      ac t = g[u][j];
      if (vis[t.v])
        continue;
      if (dis[t.v] < t.c) {
        dis[t.v] = t.c;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  while (cin >> n >> m) {
    init();
    for (int i = 1; i <= n; ++i) {
      cin >> a[i].first >> a[i].second;
    }
    double ans = 0;
    for (int i = 0; i < m; ++i) {
      int u, v;
      cin >> u >> v;
      int dx = a[u].first - a[v].first;
      int dy = a[u].second - a[v].second;
      double temp = sqrt(dx * dx + dy * dy);
      ans += temp;
      g[u].push_back((ac){v, temp});
      g[v].push_back((ac){u, temp});
      join(u, v);
    }
    for (int i = 1; i <= n; ++i) {
      if (pre[i] == i) {
        sum = 0;
        prim(i);
        ans -= sum;
      }
    }
    printf("%.3lf\n", ans);
    for (int i = 1; i <= n; ++i) {
      g[i].clear();
    }
  }
  return 0;
}
accuracy: 1
time_ms: 230
memory_kb: 9008
final_rank: 20

code_snippet: #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
struct node {
  int x, y;
} no[10005];
struct edge {
  int from, to;
  double dis;
} ed[200000];
bool cmp(const edge &a, const edge &b) { return a.dis > b.dis; }
int father[10005];
int find(int who) {
  if (who == father[who])
    return who;
  else
    return father[who] = find(father[who]);
}
int main(void) {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> no[i].x >> no[i].y;
    father[i] = i;
  }
  double ans = 0;
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    ed[i].from = a;
    ed[i].to = b;
    ed[i].dis = pow(pow(no[a].x - no[b].x, 2) + pow(no[a].y - no[b].y, 2), 0.5);
    ans += ed[i].dis;
  }
  sort(ed + 1, ed + 1 + m, cmp);
  for (int i = 1; i <= m; i++) {
    int x = find(ed[i].from);
    int y = find(ed[i].to);
    if (x != y) {
      if (x < y)
        father[x] = father[y];
      else
        father[y] = father[x];
      ans -= ed[i].dis;
    }
  }
  printf("%.3lf", ans);
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3956
final_rank: 4

code_snippet: #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
const int maxn = 1e4 + 10;
const int maxe = maxn * maxn / 2 + 10;
typedef pair<int, int> Point;
struct edge {
  int u, v;
  double dis;
  bool operator<(const edge &e) const { return dis > e.dis; }
};
Point p[maxn];
edge e[maxe];
int s[maxn];
int N, M;
double getdis(Point a, Point b) {
  double x = a.first - b.first;
  double y = a.second - b.second;
  double dis = sqrt(x * x + y * y);
  return dis;
}
int find(int x) {
  if (s[x] < 0)
    return x;
  return s[x] = find(s[x]);
}
bool same(int x, int y) {
  int a = find(x);
  int b = find(y);
  return a == b;
}
void unite(int x, int y) {
  int a = find(x);
  int b = find(y);
  if (a == b)
    return;
  if (s[b] < s[a]) {
    s[a] = b;
    return;
  }
  if (s[b] == s[a])
    s[a]--;
  s[b] = a;
}
double kruskal(double tot) {
  memset(s, -1, sizeof(s));
  sort(e, e + M);
  double res = 0;
  for (int i = 0; i < M; i++) {
    if (!same(e[i].u, e[i].v)) {
      unite(e[i].u, e[i].v);
      res += e[i].dis;
    }
  }
  return tot - res;
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    p[i].first = x;
    p[i].second = y;
  }
  double tot = 0;
  for (int i = 0; i < M; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    e[i].u = u;
    e[i].v = v;
    e[i].dis = getdis(p[u], p[v]);
    tot += e[i].dis;
  }
  double res = kruskal(tot);
  printf("%0.3f\n", res);
}
accuracy: 1
time_ms: 10
memory_kb: 3756
final_rank: 2

code_snippet: #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef pair<double, int> Pdi;
#define N 10000
struct fence {
  int to;
  double cost;
};
double distance(int x1, int y1, int x2, int y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
int main() {
  int n, m;
  P piles[N];
  vector<fence> fences[N];
  double costsum = 0;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    piles[i] = P(x, y);
  }
  for (int i = 0; i < m; i++) {
    int p, q;
    scanf("%d%d", &p, &q);
    p--;
    q--;
    double c = distance(piles[p].first, piles[p].second, piles[q].first,
                        piles[q].second);
    fences[p].push_back((fence){q, c});
    fences[q].push_back((fence){p, c});
    costsum += c;
  }
  double sum = 0;
  bool used[N];
  fill(used, used + n, false);
  priority_queue<Pdi> que;
  for (int i = 0; i < n; i++) {
    if (!used[i]) {
      que.push(Pdi(0, i));
      while (que.size()) {
        Pdi p = que.top();
        que.pop();
        int pos = p.second;
        if (used[pos])
          continue;
        used[pos] = true;
        sum += p.first;
        for (int j = 0; j < fences[pos].size(); j++) {
          que.push(Pdi(fences[pos][j].cost, fences[pos][j].to));
        }
      }
    }
  }
  printf("%.3f\n", costsum - sum);
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 5308
final_rank: 14

code_snippet: #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
#define MAX_N 10000 + 16
int parent[MAX_N];
int height[MAX_N];
void init(const int &n) {
  for (int i = 0; i < n; ++i) {
    parent[i] = i;
    height[i] = 0;
  }
}
int find(const int &x) {
  if (parent[x] == x) {
    return x;
  } else {
    return parent[x] = find(parent[x]);
  }
}
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) {
    return;
  }
  if (height[x] < height[y]) {
    parent[x] = y;
  } else {
    parent[y] = x;
    if (height[x] == height[y]) {
      ++height[x];
    }
  }
}
bool same(const int &x, const int &y) { return find(x) == find(y); }
#define MAX_E MAX_N *MAX_N / 2 + 1
struct edge {
  int u, v;
  double cost;
  edge(int u = 0, int v = 0, double cost = 0) : u(u), v(v), cost(cost) {}
  bool operator<(const edge &e2) const { return cost > e2.cost; }
};
edge es[MAX_E];
int V, E;
double kruskal() {
  sort(es, es + E);
  init(V);
  double res = 0;
  for (int i = 0; i < E; ++i) {
    edge e = es[i];
    if (!same(e.u, e.v)) {
      unite(e.u, e.v);
    } else {
      res += e.cost;
    }
  }
  return res;
}
pair<int, int> pile[MAX_N];
int main(int argc, char *argv[]) {
  cin >> V >> E;
  for (int i = 0; i < V; ++i) {
    cin >> pile[i].first >> pile[i].second;
  }
  for (int i = 0; i < E; ++i) {
    cin >> es[i].u >> es[i].v;
    --es[i].u;
    --es[i].v;
    int dx = pile[es[i].u].first - pile[es[i].v].first;
    int dy = pile[es[i].u].second - pile[es[i].v].second;
    es[i].cost = sqrt(dx * dx + dy * dy);
  }
  cout.setf(ios::showpoint);
  cout.precision(3);
  cout.setf(ios::fixed);
  cout << kruskal() << endl;
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 6032
final_rank: 16

code_snippet: #include <algorithm>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
#define EPS (1e-10)
#define EQ(a, b) ((abs((a) - (b))) < EPS)
typedef complex<double> P;
struct edge {
  int to;
  double cost;
};
int n, m;
vector<edge> G[10001];
vector<edge> G2[10001];
P points[10001];
const double INF = 1000000000;
double mincost[10001];
bool used[10001];
double prim(int s, int V) {
  for (int i = 0; i < V; i++)
    mincost[i] = INF;
  mincost[s] = 0;
  double res = 0;
  while (1) {
    int v = -1;
    for (int u = 0; u < V; u++)
      if (!used[u] && (v == -1 || mincost[u] < mincost[v]))
        v = u;
    if (v == -1 || EQ(mincost[v], INF))
      break;
    used[v] = true;
    res += mincost[v];
    for (int i = 0; i < (int)G[v].size(); i++) {
      int u = G[v][i].to;
      mincost[u] = min(mincost[u], G[v][i].cost);
    }
  }
  return res;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    points[i] = P(x, y);
  }
  double sum = 0;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    b--;
    a--;
    edge e;
    e.to = b;
    e.cost = -abs(points[a] - points[b]);
    sum += -e.cost;
    G[a].push_back(e);
    e.to = a;
    G[b].push_back(e);
  }
  double res = 0;
  for (int i = 0; i < n; i++) {
    if (used[i])
      continue;
    res += prim(i, n);
  }
  printf("%.10f\n", sum + res);
  return 0;
}
accuracy: 1
time_ms: 240
memory_kb: 5356
final_rank: 19