alexjercan/bugnet huggingface dataset:
Problem p01341 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
vector<pair<int, double>> X[12000];
int N, M, a, b;
double x[12000], y[12000], d[12000];
int g[12000];
int main() {
  cin >> N >> M;
  double S = 0;
  for (int i = 1; i <= N; i++)
    cin >> x[i] >> y[i];
  for (int i = 1; i <= M; i++) {
    cin >> a >> b;
    double c = pow((x[a] - x[b]), 2) + pow(y[a] - y[b], 2);
    c = sqrt(c);
    X[a].push_back(make_pair(b, c));
    S += c;
    X[b].push_back(make_pair(a, c));
  }
  for (int t = 1; t <= N; t++) {
    if (g[t] >= 2)
      continue;
    d[t] = 0;
    g[t] = 1;
    while (true) {
      int OK = 1;
      for (int i = 1; i <= N; i++) {
        if (g[i] == 1)
          OK = 0;
      }
      if (OK == 1)
        break;
      double maxn = -1;
      int maxid = 0;
      for (int i = 1; i <= N; i++) {
        if (g[i] == 1 && maxn < d[i]) {
          maxn = d[i];
          maxid = i;
        }
      }
      g[maxid] = 2;
      for (int i = 0; i < X[maxid].size(); i++) {
        int to = X[maxid][i].first;
        double dist = X[maxid][i].second;
        if (g[to] <= 1 && d[to] < dist) {
          d[to] = dist;
          g[to] = 1;
        }
      }
    }
  }
  double sum = 0;
  for (int i = 2; i <= N; i++) {
    sum += d[i];
  }
  printf("%.50f", S - sum);
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
vector<pair<int, double>> X[120];
int N, M, a, b;
double x[120], y[120], d[120];
int g[120];
int main() {
  cin >> N >> M;
  double S = 0;
  for (int i = 1; i <= N; i++)
    cin >> x[i] >> y[i];
  for (int i = 1; i <= M; i++) {
    cin >> a >> b;
    double c = pow((x[a] - x[b]), 2) + pow(y[a] - y[b], 2);
    c = sqrt(c);
    X[a].push_back(make_pair(b, c));
    S += c;
    X[b].push_back(make_pair(a, c));
  }
  d[1] = 0;
  g[1] = 1;
  while (true) {
    int OK = 1;
    for (int i = 1; i <= N; i++) {
      if (g[i] <= 1)
        OK = 0;
    }
    if (OK == 1)
      break;
    double maxn = -1;
    int maxid = 0;
    for (int i = 1; i <= N; i++) {
      if (g[i] == 1 && maxn < d[i]) {
        maxn = d[i];
        maxid = i;
      }
    }
    g[maxid] = 2;
    for (int i = 0; i < X[maxid].size(); i++) {
      int to = X[maxid][i].first;
      double dist = X[maxid][i].second;
      if (g[to] <= 1 && d[to] < dist) {
        d[to] = dist;
        g[to] = 1;
      }
    }
  }
  double sum = 0;
  for (int i = 2; i <= N; i++) {
    sum += d[i];
  }
  printf("%.50f", S - sum);
  return 0;
}
Problem p01341 (C++) — buggy submission, verdict: Runtime Error

// kruskal tree
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;
#define M 99999
int parent[M], a[M], b[M];
pair<double, int> node[M];
int root(int a) { return parent[a] == a ? a : parent[a] = root(parent[a]); }
int unite(int a, int b) {
  int x = root(a), y = root(b);
  if (x == y)
    return 0;
  parent[x] = y;
  return 1;
}
int main() {
  double s = 0;
  int i, n, m;
  scanf("%d%d", &n, &m);
  vector<pair<double, double>> v(n);
  for (i = 0; i < n; i++)
    scanf("%lf%lf", &v[i].first, &v[i].second);
  for (i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y), x--, y--;
    a[i] = x, b[i] = y;
    node[i].first = -hypot(v[x].first - v[y].first, v[x].second - v[y].second);
    s -= node[i].first;
    node[i].second = i;
  }
  sort(node, node + m);
  for (i = 0; i < n; i++)
    parent[i] = i;
  for (i = 0; i < m; i++)
    if (unite(a[node[i].second], b[node[i].second]))
      s += node[i].first;
  printf("%f\\n", s);
}

Error: WA

Fixed submission:

// kruskal tree
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;
#define M 10000
int parent[M], a[M], b[M];
pair<double, int> node[M];
int root(int a) { return parent[a] == a ? a : parent[a] = root(parent[a]); }
int unite(int a, int b) {
  int x = root(a), y = root(b);
  if (x == y)
    return 0;
  parent[x] = y;
  return 1;
}
int main() {
  double s = 0;
  int i, n, m;
  scanf("%d%d", &n, &m);
  vector<pair<double, double>> v(n);
  for (i = 0; i < n; i++)
    scanf("%lf%lf", &v[i].first, &v[i].second);
  for (i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y), x--, y--;
    a[i] = x, b[i] = y;
    node[i].first = -hypot(v[x].first - v[y].first, v[x].second - v[y].second);
    s -= node[i].first;
    node[i].second = i;
  }
  sort(node, node + m);
  for (i = 0; i < n; i++)
    parent[i] = i;
  for (i = 0; i < m; i++)
    if (unite(a[node[i].second], b[node[i].second]))
      s += node[i].first;
  printf("%f\\n", s);
}
Problem p01341 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define MAXN 50100
using namespace std;
int x[MAXN], y[MAXN];
struct edge {
  int from, to;
  double quan;
} e[MAXN * 2];
int n, m;
int fa[MAXN];

int find(int x) {
  if (fa[x] != x)
    fa[x] = find(fa[x]);
  return fa[x];
}

double getdis(int f, int s) {
  return sqrt((x[f] - x[s]) * (x[f] - x[s]) + (y[f] - y[s]) * (y[f] - y[s]));
}

bool cmp(edge x, edge y) { return x.quan > y.quan; }

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    cin >> x[i] >> y[i]; // scanf("%f%f",&x[i],&y[i]);
  double ans = 0;
  for (int i = 1; i <= n; i++)
    fa[i] = i;
  for (int i = 1; i <= m; i++) {
    int xx, yy;
    scanf("%d%d", &xx, &yy);
    double dis = getdis(xx, yy);
    e[i].from = xx, e[i].to = yy, e[i].quan = dis;
    ans += dis;
  }
  sort(e + 1, e + m + 1, cmp);
  for (int i = 1; i <= m; i++) {
    int xx = find(e[i].from), yy = find(e[i].to);
    if (fa[xx] != fa[yy]) {
      fa[xx] = yy;
      ans -= e[i].quan;
    }
  }
  printf("%0.3f", ans);
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define il inline
#define RG register
#define ll long long
#define db double
#define N 15010
using namespace std;
int fa[N];
int x[N], y[N];
db dis(int a, int b) {
  return sqrt((x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b]));
}
struct ee {
  int u, v;
  db k;
} e[N];
int n, m;
int find(int x) {
  if (fa[x] != x)
    x = find(fa[x]);
  return fa[x];
}
bool comp(const ee &a, const ee &b) { return a.k > b.k; }
db sum = 0.0;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i)
    scanf("%d%d", &x[i], &y[i]), fa[i] = i;
  for (int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    e[i] = (ee){u, v, dis(u, v)};
    sum += dis(u, v);
  }
  sort(e + 1, e + m + 1, comp);
  int cnt(0);
  db Ans = 0.0;
  for (int i = 1; i <= m; ++i) {
    int u = e[i].u, v = e[i].v;
    u = find(u), v = find(v);
    if (v != u)
      Ans += e[i].k, fa[u] = v, cnt++;
    if (cnt == n - 1)
      break;
  }
  printf("%.3lf", sum - Ans);
  return 0;
}
Problem p01341 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(), (c).end())

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

using namespace std;
class UnionFind {
  vector<int> p;

public:
  UnionFind(int n) : p(n, -1) {}
  int root(int x) { return p[x] < 0 ? x : p[x] = root(p[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 (p[y] < p[x])
      swap(x, y);
    if (p[x] == p[y])
      --p[x];
    p[y] = x;
    return true;
  }
};
double norm(double x, double y) { return sqrt(x * x + y * y); }
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<double> x(n), y(n);
  REP(i, n) cin >> x[i] >> y[i];
  vector<tuple<double, int, int>> e(m);
  REP(i, m) {
    int l, r;
    cin >> l >> r;
    --l;
    --r;
    double nlen = -norm(x[r] - x[l], y[r] - y[l]);
    e[i] = make_tuple(nlen, l, r);
  }
  SORT(e);
  UnionFind uf = UnionFind(n);
  double answer = 0.0;
  REP(i, m) {
    double nlen;
    int l, r;
    tie(nlen, l, r) = e[i];
    if (!uf.unite(l, r))
      answer -= nlen;
  }
  cout << fixed << answer << endl;
  return 0;
}

Error: 0

Fixed submission:

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

#define db double
#define ll long long
#define RG register

inline int gi() {
  RG int ret;
  RG bool flag;
  RG char ch;
  ret = 0, flag = true, ch = getchar();
  while (ch < '0' || ch > '9')
    ch == '-' ? flag = false : 0, ch = getchar();
  while (ch >= '0' && ch <= '9')
    ret = (ret << 3) + (ret << 1) + ch - '0', ch = getchar();
  return flag ? ret : -ret;
}

const db pi = acos(-1.0);
const int N = 1e4 + 5, inf = 1 << 30;

struct poi {
  int x, y;
} p[N];
struct edge {
  int fr, to;
  db dis;
  inline bool operator<(const edge &E) const { return dis > E.dis; }
} e[N << 1];
int fa[N];

inline db Dis(int a, int b) {
  return sqrt((p[a].x - p[b].x) * (p[a].x - p[b].x) +
              (p[a].y - p[b].y) * (p[a].y - p[b].y));
}

inline int find(int o) { return fa[o] == o ? o : fa[o] = find(fa[o]); }

int main() {
  int n, m, i, x, y;
  db ans, len;
  n = gi(), m = gi();
  for (i = 1; i <= n; ++i)
    p[i].x = gi(), p[i].y = gi();
  ans = 0;
  for (i = 1; i <= m; ++i)
    e[i].fr = x = gi(), e[i].to = y = gi(), e[i].dis = len = Dis(x, y),
    ans += len;
  sort(e + 1, e + m + 1);
  for (i = 1; i <= n; ++i)
    fa[i] = i;
  for (i = 1; n > 1 && i <= m; ++i) {
    x = e[i].fr, y = e[i].to;
    x = find(x), y = find(y);
    if (x != y)
      ans -= e[i].dis, fa[x] = y, n--;
  }
  printf("%.3f\\n", ans);
  return 0;
}
Problem p01341 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;

int n, m, cnt;
int f[10010];
struct Point {
  int x, y, id;
} point[10010];

struct Edge {
  int form, to;
  double dis;
} edge[10010 * 10010];

int Find(int x) { return f[x] == x ? x : f[x] = Find(f[x]); }

void Union(int x, int y) {
  int fx = Find(x);
  int fy = Find(y);
  if (fx != fy)
    f[fy] = fx;
}
void Addedge(int form, int to, double dis) {
  edge[cnt].form = form;
  edge[cnt].to = to;
  edge[cnt++].dis = dis;
}

double dis(Point x, Point y) {
  return sqrt(1.0 * (x.x - y.x) * (x.x - y.x) +
              1.0 * (x.y - y.y) * (x.y - y.y));
}
bool cmp1(Edge a, Edge b) { return a.dis > b.dis; }

bool cmp2(double a, double b) { return a < b; }

double Kruskal() {
  sort(edge, edge + cnt, cmp1);
  for (int i = 1; i <= n; i++)
    f[i] = i;
  double sum = 0;
  int tot = 0;
  int i;
  for (i = 0; i < cnt; i++) {
    if (Find(edge[i].form) == Find(edge[i].to)) {
      sum += edge[i].dis;
      continue;
    }
    Union(edge[i].form, edge[i].to);
  }
  return sum;
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    cnt = 0;
    for (int i = 1; i <= n; i++) {
      cin >> point[i].x >> point[i].y;
      point[i].id = i;
    }
    for (int i = 1; i <= m; i++) {
      int a, b;
      double w;
      cin >> a >> b;
      w = dis(point[a], point[b]);
      Addedge(a, b, w);
    }
    printf("%.3f\\n", Kruskal());
  }
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <stdio.h>
using namespace std;
const int maxn = 50010;
int pre[20010];
int t, n, m, r;
struct edge {
  int a, b, v;
} ed[maxn];
bool cmp(edge a, edge b) { return a.v > b.v; }
int Find(int x) {
  int p, tmp;
  p = x;
  while (x != pre[x])
    x = pre[x];
  while (p != x) {
    tmp = pre[p];
    pre[p] = x;
    p = tmp;
  }
  return x;
}
void Union(int x, int y) {
  int p = Find(x);
  int q = Find(y);
  if (p != q)
    pre[q] = p;
}
void init() {
  for (int i = 0; i <= m + n; i++)
    pre[i] = i;
}
void kruskal() {
  long long int ans = 10000 * (m + n);
  init();
  for (int i = 1; i <= r; i++) {
    int x = ed[i].a, y = ed[i].b;
    if (Find(x) != Find(y)) {
      Union(x, y);
      ans -= ed[i].v;
    }
  }
  printf("%lld\\n", ans);
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d%d", &n, &m, &r);
    for (int i = 1; i <= r; i++) {
      int x, y, d;
      scanf("%d%d%d", &x, &y, &d);
      ed[i].a = x;
      ed[i].b = y + n;
      ed[i].v = d;
    }
    sort(ed + 1, ed + m + 1, cmp);
    kruskal();
  }
  return 0;
}
Problem p01341 (C++) — buggy submission, verdict: Runtime Error

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

struct nodeI {
  double x;
  double y;
};

struct nodeII {
  int u;
  int v;
  double w;
};

nodeI point[10010];
nodeII edge[1000010];
int f[10010];
int n, m;

double cal(int u, int v) {
  double sum;
  sum = sqrt((point[u].x - point[v].x) * (point[u].x - point[v].x) +
             (point[u].y - point[v].y) * (point[u].y - point[v].y));
  return sum;
}

int cmp(nodeII n1, nodeII n2) { return n1.w > n2.w; }

int getf(int p) {
  if (f[p] == p) {
    return p;
  } else {
    f[p] = getf(f[p]);
    return f[p];
  }
}

int unite(int u, int v) {
  int fu, fv;
  fu = getf(u);
  fv = getf(v);
  if (fu != fv) {
    f[fv] = fu;
    return 1;
  } else {
    return 0;
  }
}

int main() {
  double sum1, sum2;
  int i, cnt;
  while (scanf("%d%d", &n, &m) != EOF) {
    for (i = 1; i <= n; i++) {
      scanf("%lf%lf", &point[i].x, &point[i].y);
    }
    sum1 = 0;
    for (i = 1; i <= m; i++) {
      scanf("%d%d", &edge[i].u, &edge[i].v);
      edge[i].w = cal(edge[i].u, edge[i].v);
      sum1 += edge[i].w;
    }
    for (i = 1; i <= n; i++) {
      f[i] = i;
    }
    sort(edge + 1, edge + m + 1, cmp);
    sum2 = 0, cnt = 0;
    for (i = 1; i <= m; i++) {
      if (unite(edge[i].u, edge[i].v)) {
        sum2 += edge[i].w;
        cnt++;
      }
      if (cnt == n - 1)
        break;
    }
    printf("%.3f\\n", sum1 - sum2);
  }
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 10005;
struct E {
  int u, v;
  double w;
  bool operator<(const E &A) const { return w > A.w; }
  E(int _u = 0, int _v = 0, double _w = 0) {
    u = _u;
    v = _v;
    w = _w;
  }
} edge[maxn];

int x[maxn], y[maxn];
int n, m;
double Distance(int u, int v) {
  return sqrt(1.0 * (x[u] - x[v]) * (x[u] - x[v]) +
              1.0 * (y[u] - y[v]) * (y[u] - y[v]));
}
int fa[maxn];
int Find(int x) {
  if (fa[x] != x)
    fa[x] = Find(fa[x]);
  return fa[x];
}
double kruscal() {
  for (int i = 1; i <= n; i++)
    fa[i] = i;
  double mst = 0;
  for (int i = 1; i <= m; i++) {
    int u = Find(edge[i].u), v = Find(edge[i].v);
    if (u == v)
      continue;
    fa[u] = v;
    mst += edge[i].w;
  }
  return mst;
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 1; i <= n; i++)
      scanf("%d%d", &x[i], &y[i]);
    double ans = 0;
    for (int i = 1; i <= m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      double d = Distance(u, v);
      edge[i] = E(u, v, d);
      ans += d;
    }
    sort(edge + 1, edge + 1 + m);
    ans -= kruscal();
    printf("%.10f\\n", ans);
  }

  return 0;
}
Problem p01341 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = int(1e7) + 5;
int n, m;
int fa[MAXN];
struct node {
  int u, v;
  double val;
} e[MAXN];
int cmp(node a, node b) { return a.val > b.val; }
void Init() {
  for (int i = 0; i < MAXN; i++)
    fa[i] = i;
}
int Find(int x) {
  if (x == fa[x])
    return x;
  return fa[x] = Find(fa[x]);
}
bool Merge(int x, int y) {
  int fx = Find(x), fy = Find(y);
  if (fx != fy) {
    fa[fx] = fy;
    return 1;
  }
  return 0;
}
int cor[MAXN][3];
void Build(double &ans) {
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &cor[i][1], &cor[i][2]);
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    e[i].u = a - 1, e[i].v = b - 1;
    e[i].val = sqrt((cor[a][1] - cor[b][1]) * (cor[a][1] - cor[b][1]) +
                    (cor[a][2] - cor[b][2]) * (cor[a][2] - cor[b][2]));
    ans += e[i].val;
  }
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    Init();
    double ans = -1;
    Build(ans);
    sort(e + 1, e + m + 1, cmp);
    for (int i = 1; i <= m; i++)
      if (Merge(e[i].u, e[i].v))
        ans -= e[i].val;
    printf("%.3lf\\n", ans + 1.0);
  }
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define _for(i, a, b) for (int i = (a); i < (b); i++)
#define _rep(i, a, b) for (int i = (a); i > (b); i--)
#define _for1(i, a, b) for (int i = (a); i <= (b); i++)
#define _rep1(i, a, b) for (int i = (a); i >= (b); i--)
using namespace std;
const int MAXN = 10000; //  最大点数
int F[MAXN + 10];       //  并查集使用
struct Edge {
  int u;           //  起点
  int v;           //  终点
  double w;        //  权值
} edge[MAXN + 10]; // 存储边的信息
struct node {
  int x, y;
};
struct node T[MAXN + 10];
int tol; //  边数，加边前赋值为0
void addEdge(int u, int v, double w) {
  edge[tol].u = u;
  edge[tol].v = v;
  edge[tol++].w = w;
}
bool cmp(Edge a, Edge b) {
  //  排序函数，将边按照权值从小到大排序
  return a.w > b.w;
}
int find(int x) {
  if (F[x] == x)
    return x;
  else
    return F[x] = find(F[x]);
}
double Kruskal(int n) //  传入点数，返回最小生成树的权值，如果不连通则返回-1
{
  for (int i = 0; i <= n; i++)
    F[i] = i;
  sort(edge, edge + tol, cmp);
  int cnt = 0; //  计算加入的边数
  double ans = 0;
  for (int i = 0; i < tol; i++) {
    int u = edge[i].u;
    int v = edge[i].v;
    double w = edge[i].w;
    int tOne = find(u);
    int tTwo = find(v);
    if (tOne != tTwo) {
      ans += w;
      F[tOne] = tTwo;
    }
  }
  return ans;
}
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    memset(edge, 0, sizeof(edge));
    _for(i, 0, n) scanf("%d%d", &T[i].x, &T[i].y);
    double sum = 0.0;
    _for(i, 0, m) {
      int p, q;
      scanf("%d%d", &p, &q);
      double distant =
          sqrt((T[p - 1].x - T[q - 1].x) * (T[p - 1].x - T[q - 1].x) +
               (T[p - 1].y - T[q - 1].y) * (T[p - 1].y - T[q - 1].y));
      addEdge(p, q, distant);
      sum += distant;
    }
    sum -= Kruskal(n);
    printf("%.3lf\\n", sum);
  }
  return 0;
}
Problem p01341 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

const int maxn = 10000 + 5;
pair<int, int> P[maxn];
struct Edge {
  int from, to;
  double cost;
  Edge() {}
  Edge(int a, int b, double c) : from(a), to(b), cost(c) {}
};
Edge es[maxn * 100];
int N, M, father[maxn];
double res;

void init() {
  for (int i = 1; i <= N; ++i)
    father[i] = i;
}

bool cmp(Edge a, Edge b) { return a.cost > b.cost; }

int find(int x) {
  if (x == father[x])
    return x;
  int temp = father[x];
  father[x] = find(father[x]);
  x = temp;
  return father[x];
}

void Kruskal() {
  sort(es + 1, es + 1 + M, cmp);
  init();
  //    for(int i=1;i<=M;++i)
  //        printf("%d %d %.3lf\\n",es[i].from,es[i].to,es[i].cost);
  double ans = 0;
  for (int i = 1; i <= M; ++i) {
    Edge e = es[i];
    int x = find(e.from), y = find(e.to);
    //        cout<<"before : "<<e.from<<" "<<e.to<<" "<<x<<" "<<y<<endl;
    if (x != y) {
      father[x] = y;
      ans += e.cost;
      //            cout<<"after : "<<x<<" "<<y<<" "<<find(x)<<"
      //            "<<find(y)<<endl;
    }
  }
  //    cout<<res<<" "<<ans<<endl;
  printf("%.3lf\\n", res - ans);
}

int main() {
  res = 0;
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; ++i) {
    scanf("%d%d", &P[i].first, &P[i].second);
  }
  for (int i = 1; i <= M; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    double temp =
        sqrt((P[a].first - P[b].first) * (P[a].first - P[b].first) +
             (P[a].second - P[b].second) * (P[a].second - P[b].second));
    res += temp;
    es[i] = Edge(a, b, temp);
  }
  Kruskal();
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
#define maxn 10010
#define INF 0x7fffffff
using namespace std;
struct node {
  double x, y;
} mapp[maxn];
int m, n;
double Map[10001][10001], dis[maxn * maxn], sum1 = 0.0;
bool vis[maxn];
void prim() {
  memset(vis, false, sizeof(vis));
  memset(dis, 0, sizeof(dis));
  int pt = 1;
  double mam;
  vis[1] = 1;
  dis[1] = 0.0;
  while (1) {
    for (int i = 1; i <= n; i++)
      if (!vis[i] && dis[i] < Map[pt][i])
        dis[i] = Map[pt][i];
    pt = -1;
    mam = -1;
    for (int i = 1; i <= n; i++) {
      if (!vis[i] && dis[i] > mam) {
        mam = dis[i];
        pt = i;
      }
    }
    if (pt == -1)
      break;
    sum1 = sum1 + mam;
    vis[pt] = true;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  {
    memset(mapp, 0, sizeof(mapp));
    memset(Map, 0, sizeof(Map));
    sum1 = 0.0;
    for (int i = 1; i <= n; i++)
      scanf("%lf%lf", &mapp[i].x, &mapp[i].y);
    int x, y;
    double sum = 0.0;
    for (int i = 0; i < m; i++) {
      scanf("%d%d", &x, &y);
      Map[x][y] = Map[y][x] =
          sqrt((mapp[x].x - mapp[y].x) * (mapp[x].x - mapp[y].x) +
               (mapp[x].y - mapp[y].y) * (mapp[x].y - mapp[y].y));
      sum += Map[x][y];
      // printf("坐?：%d %d;?? %.3f\\n",x,y,Map[x][y]);
    }
    prim();
    printf("%.3f\\n", sum - sum1);
  }
}
Problem p01341 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
#define inf 0x3f3f3f
#define N 10000
int fa[2 * N + 5], t, n, m, k;
double s[N + 5][2], s1;
struct mzls {
  int u, v;
  double w;
  bool operator<(const mzls &a) const { return a.w < w; }
} g[N * N + 5], as;
inline int find(int x) {
  if (fa[x] == -1)
    return x;
  return fa[x] = find(fa[x]);
}
inline double K() {
  double sum = 0.0;
  sort(g + 1, g + t + 1);
  memset(fa, -1, sizeof(fa));
  int j = 0;
  for (int i = 1; i <= t; i++) {
    int u = g[i].u, v = g[i].v;
    int r1 = find(u), r2 = find(v);
    if (r1 != r2) {
      fa[r2] = r1;
      sum += g[i].w;
      j++;
      if (j >= n - 1)
        break;
    }
  }
  return sum;
}
inline void insert(int x, int y, double z) {
  as.u = x, as.v = y, as.w = z;
  g[++t] = as;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%lf%lf", &s[i][0], &s[i][1]);
  for (int i = 1; i <= m; i++) {
    int x, y;
    double z;
    scanf("%d%d", &x, &y);
    z = sqrt((s[x][1] - s[y][1]) * (s[x][1] - s[y][1]) +
             (s[x][0] - s[y][0]) * (s[x][0] - s[y][0]));
    s1 += z;
    insert(x, y, z);
  }
  printf("%lf\\n", s1 - K());
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define MAXN 2000
#define MAXM 10000
struct pos {
  int x, y;
} P[MAXN * 2 + 5];
struct node {
  int x, y;
  double price;
} a[MAXM * 5 + 5];
int n, m, T;
int p, father[MAXN * 2 + 5];
int num, cont;
double ans = 0, sum;
void fpush(int u, int v, double w) {
  a[++num].price = w;
  a[++num].price = w;
  a[num - 1].x = a[num].y = u;
  a[num - 1].y = a[num].x = v;
}
bool cmp(node s1, node s2) { return s1.price > s2.price; }
int xfind(int p) {
  if (father[p] != p)
    father[p] = xfind(father[p]);
  return father[p];
}
int bin(int p1, int p2) { father[p2] = p1; }
int main() {
  scanf("%d%d", &n, &m);
  cont = 0, num = 0, ans = 0;
  ;
  memset(father, 0, sizeof(father));
  bin(0, 0);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &P[i].x, &P[i].y);
    bin(i, i);
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    double dist;
    scanf("%d%d", &u, &v);
    dist = sqrt((double)(P[u].x - P[v].x) * (P[u].x - P[v].x) +
                (double)(P[u].y - P[v].y) * (P[u].y - P[v].y));
    sum += dist;
    fpush(u, v, dist);
  }
  sort(a + 1, a + num + 1, cmp);
  for (int i = 1; i <= num; i++) {
    if (cont == n - 1)
      break;
    int s1 = xfind(a[i].x), s2 = xfind(a[i].y);
    if (s1 != s2) {
      bin(s1, s2);
      ans += a[i].price;
      cont++;
    }
  }
  printf("%.3lf\\n", sum - ans);
}