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

#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

int memo[3][301];

int main() {
  for (int n, m; cin >> n >> m;) {
    for (int i = 0; i < 3; i++)
      for (int j = 0; j <= m; j++)
        memo[i][j] = (j ? -1 : 0);

    int ans = 0;
    while (n--) {
      getchar();
      while (getchar() != '\\n')
        ;
      int cost, prm[3];
      cin >> cost >> prm[0] >> prm[1] >> prm[2];
      //			scanf("%d%d%d%d ",&cost,prm,prm+1,prm+2);
      for (int i = 0; i < 3; i++)
        for (int j = 0; j + cost <= m; j++) {
          if (memo[i][j] == -1)
            continue;
          memo[i][j + cost] = max(memo[i][j + cost], memo[i][j] + prm[i]);
          ans = max(ans, memo[i][j + cost]);
        }
    }
    printf("%d\\n", ans);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>

using namespace std;

int memo[3][301];

int main() {
  for (int n, m; ~scanf("%d%d ", &n, &m);) {
    for (int i = 0; i < 3; i++)
      for (int j = 0; j <= m; j++)
        memo[i][j] = (j ? -1 : 0);

    int ans = 0;
    while (n--) {
      while (getchar() != '\\n')
        ;
      int cost, prm[3];
      scanf("%d%d%d%d ", &cost, prm, prm + 1, prm + 2);
      for (int i = 0; i < 3; i++)
        for (int j = 0; j + cost <= m; j++) {
          if (memo[i][j] == -1)
            continue;
          memo[i][j + cost] = max(memo[i][j + cost], memo[i][j] + prm[i]);
          ans = max(ans, memo[i][j + cost]);
        }
    }
    printf("%d\\n", ans);
  }

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

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

int dp[40][1 << 14];
int v[40];

int pnt(int c) { return c > 0 ? 50 + c * 10 : 0; }

int toBit(int c[7], int p) {
  int bit = 0;
  for (int i = 1; i < 7; i++) {
    bit = (bit << 2) | c[i];
  }
  bit = (bit << 2) | (~v[p + 7] ? v[p + 7] : 0);
  return bit;
}

void solve() {
  memset(v, -1, sizeof(v));
  for (int i = 0; i < 25; i++)
    cin >> v[i], v[i]--;
  memset(dp, -1, sizeof(dp));
  int start = 0;
  for (int i = 0; i < 7; i++)
    start = (start << 2) | (~v[i] ? v[i] : 0);
  dp[0][start] = 0;
  for (int i = 0; i < 25; i++) {

    for (int S = 0; S < (1 << 14); S++) {
      if (dp[i][S] == -1)
        continue;
      int c[7];
      for (int j = 0; j < 7; j++)
        c[6 - j] = S >> (j * 2) & 3;

      if (i % 5 == 4 || i >= 20) {
        dp[i + 1][toBit(c, i)] =
            max(dp[i + 1][toBit(c, i)], dp[i][S] + pnt(c[0]));
        continue;
      }
      for (int j = 0; j < 4; j++) {
        dp[i + 1][toBit(c, i)] =
            max(dp[i + 1][toBit(c, i)], dp[i][S] + pnt(c[0]));

        for (int k = 0; k < 7; k++)
          if (k < 2 || k >= 5) {
            if (~v[i + k])
              c[k] = (c[k] + 1) % 4;
          }
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < (1 << 14); i++)
    ans = max(ans, dp[25][i]);

  cout << ans << endl;
}

int main() {
  int n;
  cin >> n;
  while (n--)
    solve();
  return 0;
}

Error: -11

Fixed submission:

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

int dp[40][1 << 14];
int v[40];

int pnt(int c) { return c > 0 ? 50 + c * 10 : 0; }

int toBit(int c[7], int p) {
  int bit = 0;
  for (int i = 1; i < 7; i++) {
    bit = (bit << 2) | c[i];
  }
  return bit = (bit << 2) | (~v[p + 7] ? c[p + 7] : 0);
}

void solve() {
  memset(v, -1, sizeof(v));
  for (int i = 0; i < 25; i++)
    cin >> v[i], v[i]--;
  memset(dp, -1, sizeof(dp));
  int start = 0;
  for (int i = 0; i < 7; i++)
    start = (start << 2) | (~v[i] ? v[i] : 0);
  dp[0][start] = 0;
  for (int i = 0; i < 25; i++) {

    for (int S = 0; S < (1 << 14); S++) {
      int a = i;
      if (dp[i][S] == -1)
        continue;

      int c[7];
      for (int j = 0; j < 7; j++)
        c[6 - j] = S >> (j * 2) & 3;

      if (i % 5 == 4 || i >= 20) {
        dp[i + 1][toBit(c, i)] =
            max(dp[i + 1][toBit(c, i)], dp[i][S] + pnt(c[0]));
        continue;
      }
      for (int j = 0; j < 4; j++) {
        dp[i + 1][toBit(c, i)] =
            max(dp[i + 1][toBit(c, i)], dp[i][S] + pnt(c[0]));

        for (int k = 0; k < 7; k++)
          if (k < 2 || k >= 5) {
            if (~v[i + k])
              c[i + k] = (c[i + k] + 1) % 4;
          }
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < (1 << 14); i++)
    ans = max(ans, dp[25][i]);

  cout << ans << endl;
}

int main() {
  int n;
  cin >> n;
  while (n--)
    solve();
  return 0;
}
Problem p01338 (C++) — buggy submission, verdict: Runtime Error

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

int dp[40][1 << 14];
int v[40];

inline int pnt(int c) { return c > 0 ? 50 + c * 10 : 0; }

int toBit(int c[7], int p) {
  int bit = 0;
  for (int i = 1; i < 7; i++) {
    bit = (bit << 2) | c[i];
  }
  bit = (bit << 2) | (~v[p + 7] ? v[p + 7] : 0);
  return bit;
}

void solve() {
  memset(v, -1, sizeof(v));
  for (int i = 0; i < 25; i++)
    cin >> v[i], v[i]--;
  memset(dp, -1, sizeof(dp));
  int start = 0;
  for (int i = 0; i < 7; i++)
    start = (start << 2) | (~v[i] ? v[i] : 0);
  dp[0][start] = 0;
  for (int i = 0; i < 25; i++) {

    for (int S = 0; S < (1 << 14); S++) {
      if (dp[i][S] == -1)
        continue;
      int c[7];
      for (int j = 0; j < 7; j++)
        c[6 - j] = S >> (j * 2) & 3;

      int to = ((S << 2) & ((1 << 14) - 1)) | (~v[i + 7] ? v[i + 7] : 0);
      if (i % 5 == 4 || i >= 20) {
        dp[i + 1][to] = max(dp[i + 1][to], dp[i][S] + pnt(c[0]));
        continue;
      }
      for (int j = 0; j < 4; j++) {
        to = toBit(c, i);
        dp[i + 1][to] = max(dp[i + 1][to], dp[i][S] + pnt(c[0]));

        if (~v[i])
          c[0] = (c[0] + 1) % 4;
        if (~v[i + 1])
          c[1] = (c[1] + 1) % 4;
        if (~v[i + 5])
          c[5] = (c[5] + 1) % 4;
        if (~v[i + 6])
          c[6] = (c[6] + 1) % 4;
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < (1 << 14); i++)
    ans = max(ans, dp[25][i]);

  cout << ans << endl;
}

int main() {
  int n;
  cin >> n;
  while (n--)
    solve();
  return 0;
}

Error: -11

Fixed submission:

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

int dp[25][1 << 14];
int v[40];

inline int pnt(int c) { return c > 0 ? 50 + c * 10 : 0; }

int toBit(int c[7], int p) {
  int bit = 0;
  for (int i = 1; i < 7; i++) {
    bit = (bit << 2) | c[i];
  }
  bit = (bit << 2) | (~v[p + 7] ? v[p + 7] : 0);
  return bit;
}

void solve() {
  memset(v, -1, sizeof(v));
  for (int i = 0; i < 25; i++)
    cin >> v[i], v[i]--;
  memset(dp, -1, sizeof(dp));
  int start = 0;
  for (int i = 0; i < 7; i++)
    start = (start << 2) | (~v[i] ? v[i] : 0);
  dp[0][start] = 0;
  for (int i = 0; i < 25; i++) {

    for (int S = 0; S < (1 << 14); S++) {
      if (dp[i][S] == -1)
        continue;
      int c[7];
      for (int j = 0; j < 7; j++)
        c[6 - j] = S >> (j * 2) & 3;

      int to = (S << 2) | (~v[i + 7] ? v[i + 7] : 0);
      if (i % 5 == 4 || i >= 20) {
        dp[i + 1][to] = max(dp[i + 1][to], dp[i][S] + pnt(c[0]));
        continue;
      }
      for (int j = 0; j < 4; j++) {
        to = toBit(c, i);
        dp[i + 1][to] = max(dp[i + 1][to], dp[i][S] + pnt(c[0]));

        if (~v[i])
          c[0] = (c[0] + 1) % 4;
        if (~v[i + 1])
          c[1] = (c[1] + 1) % 4;
        if (~v[i + 5])
          c[5] = (c[5] + 1) % 4;
        if (~v[i + 6])
          c[6] = (c[6] + 1) % 4;
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < (1 << 14); i++)
    ans = max(ans, dp[25][i]);

  cout << ans << endl;
}

int main() {
  int n;
  cin >> n;
  while (n--)
    solve();
  return 0;
}
Problem p01341 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <vector>
#define MAX_N 10005
using namespace std;

typedef struct edge {
  int from, to, cost;
} edge;

bool mcmp(edge x, edge y) { return x.cost < y.cost; }

int uft[MAX_N];
vector<edge> e;

void init(int n) {
  int i;
  for (i = 0; i <= n; i++)
    uft[i] = i;
}

int parent(int n) {
  if (uft[n] == n)
    return n;
  else
    return uft[n] = parent(uft[n]);
}

void unit(int p, int q) { uft[parent(p)] = parent(q); }

int same(int p, int q) { return parent(p) == parent(q); }

int kruskal(int n, int r) {
  int res = 0;
  sort(e.begin(), e.end(), mcmp);
  init(n);
  for (int i = 0; i < r; i++) {
    edge tmp = e[i];
    if (!same(tmp.from, tmp.to)) {
      res += tmp.cost;
      unit(tmp.from, tmp.to);
      e[i].cost = 0;
    }
  }
  return res;
}

int piles[10001][2];
int m_distance(int f, int t) {
  return pow((double)piles[f][0] - piles[t][0], 2) +
         pow((double)piles[f][1] - piles[t][1], 2);
}

int main() {
  int N, M;
  int all_cost = 0;
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; i++)
    scanf("%d%d", &piles[i][0], &piles[i][1]);
  for (int j = 0; j < M; j++) {
    edge tmp;
    scanf("%d%d", &tmp.from, &tmp.to);
    tmp.cost = -m_distance(tmp.from, tmp.to);
    e.push_back(tmp);
  }
  kruskal(N, M);
  double res = 0.0;
  for (int i = 0; i < M; i++)
    res += sqrt(-(double)e[i].cost);
  printf("%.3lf\\n", res);
  e.clear();
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <vector>
#define MAX_N 1005
#define MAX_R 20005
using namespace std;

typedef struct edge {
  int from, to, cost;
} edge;

bool mcmp(edge x, edge y) { return x.cost < y.cost; }

int uft[MAX_N];
vector<edge> e;

void init(int n) {
  int i;
  for (i = 0; i <= n; i++)
    uft[i] = i;
}

int parent(int n) {
  if (uft[n] == n)
    return n;
  else
    return uft[n] = parent(uft[n]);
}

void unit(int p, int q) { uft[parent(p)] = parent(q); }

int same(int p, int q) { return parent(p) == parent(q); }

int kruskal(int n, int r) {
  int res = 0;
  sort(e.begin(), e.end(), mcmp);
  init(n);
  for (int i = 0; i < r; i++) {
    edge tmp = e[i];
    if (!same(tmp.from, tmp.to)) {
      res += tmp.cost;
      unit(tmp.from, tmp.to);
      e[i].cost = 0;
    }
  }
  return res;
}

int piles[10001][2];
int m_distance(int f, int t) {
  return pow((double)piles[f][0] - piles[t][0], 2) +
         pow((double)piles[f][1] - piles[t][1], 2);
}

int main() {
  int N, M;
  int all_cost = 0;
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; i++)
    scanf("%d%d", &piles[i][0], &piles[i][1]);
  for (int j = 0; j < M; j++) {
    edge tmp;
    scanf("%d%d", &tmp.from, &tmp.to);
    tmp.cost = -m_distance(tmp.from, tmp.to);
    e.push_back(tmp);
  }
  kruskal(N, M);
  double res = 0.0;
  for (int i = 0; i < M; i++)
    res += sqrt(-(double)e[i].cost);
  printf("%.3lf\\n", res);
  e.clear();
  return 0;
}
Problem p01341 (C++) — buggy submission, verdict: Runtime Error

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

struct Way {
  int p, q, cost;
  Way() {}
  Way(int _p, int _q, int _cost) {
    p = _p;
    q = _q;
    cost = _cost;
  }
  bool operator<(const Way &a) const { return cost > a.cost; }
};

struct Node {
  int x, y;
};

int par[10000], _rank[10000];

void init(int n) {
  for (int i = 0; i < n; i++)
    par[i] = i, _rank[i] = 1;
}

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

void unite(int _a, int _b) {
  int a = find(_a);
  int b = find(_b);
  if (a == b)
    return;
  if (_rank[a] > _rank[b]) {
    par[b] = a;
  } else {
    par[a] = b;
    if (_rank[a] == _rank[b])
      _rank[b]++;
  }
}

int main() {
  int N, M;
  Node node[10000];
  Way way[100000];
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> node[i].x >> node[i].y;
  }
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> way[i].p >> way[i].q;
    a = node[--way[i].p].x - node[--way[i].q].x;
    b = node[way[i].p].y - node[way[i].q].y;
    way[i].cost = a * a + b * b;
    // printf("\\t%d\\n",way[i].cost);
  }

  double ans = 0;
  sort(way, way + M);
  init(N);
  for (int i = 0; i < M; i++) {
    int a = find(way[i].p), b = find(way[i].q);
    if (a != b)
      unite(a, b);
    else
      ans += sqrt(way[i].cost);
  }
  printf("%lf\\n", ans);
}

Error: -11

Fixed submission:

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

struct Way {
  int p, q, cost;
  Way() {}
  Way(int _p, int _q, int _cost) {
    p = _p;
    q = _q;
    cost = _cost;
  }
  bool operator<(const Way &a) const { return cost > a.cost; }
};

struct Node {
  int x, y;
};

int par[10000], _rank[10000];

void init(int n) {
  for (int i = 0; i < n; i++)
    par[i] = i, _rank[i] = 1;
}

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

void unite(int _a, int _b) {
  int a = find(_a);
  int b = find(_b);
  if (a == b)
    return;
  if (_rank[a] > _rank[b]) {
    par[b] = a;
  } else {
    par[a] = b;
    if (_rank[a] == _rank[b])
      _rank[b]++;
  }
}

int main() {
  int N, M;
  Node node[10000];
  Way way[10000000];
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> node[i].x >> node[i].y;
  }
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> way[i].p >> way[i].q;
    a = node[--way[i].p].x - node[--way[i].q].x;
    b = node[way[i].p].y - node[way[i].q].y;
    way[i].cost = a * a + b * b;
    // printf("\\t%d\\n",way[i].cost);
  }

  double ans = 0;
  sort(way, way + M);
  init(N);
  for (int i = 0; i < M; i++) {
    int a = find(way[i].p), b = find(way[i].q);
    if (a != b)
      unite(a, b);
    else
      ans += sqrt(way[i].cost);
  }
  printf("%lf\\n", ans);
}
Problem p01341 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;

int N, M;

struct Node {
  int x;
  int y;
};

struct Link {
  int node1;
  int node2;
  double len;
};

bool compare(const Link &left, const Link &right);

int main(void) {
  cin >> N >> M;
  vector<vector<int>> array;
  int i, j, k, t1, t2, s, t;
  double ans = 0.0;
  struct Node nodes[N];
  struct Link links[M];

  for (i = 0; i < N; i++) {
    vector<int> temp;
    temp.push_back(i + 1);
    array.push_back(temp);
  }

  for (i = 0; i < N; i++)
    cin >> nodes[i].x >> nodes[i].y;
  for (i = 0; i < M; i++) {
    cin >> links[i].node1 >> links[i].node2;
    links[i].len = sqrt(
        pow(nodes[links[i].node1 - 1].x - nodes[links[i].node2 - 1].x, 2.0) +
        pow(nodes[links[i].node1 - 1].y - nodes[links[i].node2 - 1].y, 2.0));
  }

  sort(links, links + M, compare);

  for (i = 0; i < M; i++) {
    for (j = 0; j < array.size(); j++) {
      for (k = 0; k < array.at(j).size(); k++) {
        if (links[i].node1 == array.at(j).at(k))
          t1 = j;
        else if (links[i].node2 == array.at(j).at(k))
          t2 = j;
      }
    }
    if (t1 == t2)
      ans += links[i].len;
    else {
      if (t1 > t2)
        swap(t1, t2);
      while (!array.at(t2).empty()) {
        array.at(t1).push_back(array.at(t2).back());
        array.at(t2).pop_back();
      }
      array.erase(array.begin() + t2);
    }
  }

  printf("%.3f", ans);

  return 0;
}

bool compare(const Link &left, const Link &right) {
  return left.len > right.len;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;

int N, M;

struct Node {
  int x;
  int y;
};

struct Link {
  int node1;
  int node2;
  double len;
};

bool compare(const Link &left, const Link &right);

int main(void) {
  cin >> N >> M;
  vector<int> array[N];
  int forest[N][N], i, j, k, t1, t2, s, t;
  double ans = 0.0;
  struct Node nodes[N];
  struct Link links[M];

  for (i = 0; i < N; i++)
    array[i].push_back(i + 1);

  for (i = 0; i < N; i++)
    cin >> nodes[i].x >> nodes[i].y;
  for (i = 0; i < M; i++) {
    cin >> links[i].node1 >> links[i].node2;
    links[i].len = sqrt(
        pow(nodes[links[i].node1 - 1].x - nodes[links[i].node2 - 1].x, 2.0) +
        pow(nodes[links[i].node1 - 1].y - nodes[links[i].node2 - 1].y, 2.0));
  }

  sort(links, links + M, compare);

  for (i = 0; i < M; i++) {
    for (j = 0; j < N; j++) {
      for (k = 0; k < array[j].size(); k++) {
        if (links[i].node1 == array[j].at(k))
          t1 = j;
        else if (links[i].node2 == array[j].at(k))
          t2 = j;
      }
    }
    if (t1 == t2)
      ans += links[i].len;
    else {
      if (t1 > t2)
        swap(t1, t2);
      while (!array[t2].empty()) {
        array[t1].push_back(array[t2].back());
        array[t2].pop_back();
      }
    }
  }

  printf("%.3f", ans);

  return 0;
}

bool compare(const Link &left, const Link &right) {
  return left.len > right.len;
}
Problem p01341 (C++) — buggy submission, verdict: Runtime Error

/*
 * @Author: 王文宇
 * @Date:   2018-03-14 23:59:01
 * @Last Modified by:   王文宇
 * @Last Modified time: 2018-03-15 00:12:07
 */
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000007;
#define _for(i, a, b) for (int i = a; i <= b; i++)
int n, m, fa[maxn];
struct node {
  int x, y;
  double length;
} a[maxn];
struct point {
  int x, y;
} b[maxn];
bool cmp(node a, node b) { return a.length > b.length; }
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
double get(int x1, int x2, int y1, int y2) {
  double xx = (double)(x1 - x2) * (double)(x1 - x2);
  double yy = (double)(y1 - y2) * (double)(y1 - y2);
  return sqrt(xx + yy);
}
int main(int argc, char const *argv[]) {
  cin >> n >> m;
  _for(i, 1, n) {
    fa[i] = i;
    int x, y;
    cin >> b[i].x >> b[i].y;
  }
  double sum = 0.0;
  _for(i, 1, m) {
    int x, y;
    cin >> x >> y;
    a[i].x = x;
    a[i].y = y;
    a[i].length = get(b[x].x, b[y].x, b[x].y, b[y].y);
    sum += a[i].length;
  }
  sort(a + 1, a + 1 + m, cmp);
  _for(i, 1, m) {
    int p = find(a[i].x);
    int q = find(a[i].y);
    if (p != q) {
      sum -= a[i].length;
      fa[p] = q;
    }
  }
  printf("%.3f\\n", sum);
  return 0;
}


Error: 0

Fixed submission:

/*
 * @Author: 王文宇
 * @Date:   2018-03-14 23:59:01
 * @Last Modified by:   王文宇
 * @Last Modified time: 2018-03-15 00:12:07
 */
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10007;
#define _for(i, a, b) for (int i = a; i <= b; i++)
int n, m, fa[maxn];
struct node {
  int x, y;
  double length;
} a[maxn];
struct point {
  int x, y;
} b[maxn];
bool cmp(node a, node b) { return a.length > b.length; }
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
double get(int x1, int x2, int y1, int y2) {
  double xx = (double)(x1 - x2) * (double)(x1 - x2);
  double yy = (double)(y1 - y2) * (double)(y1 - y2);
  return sqrt(xx + yy);
}
int main(int argc, char const *argv[]) {
  cin >> n >> m;
  _for(i, 1, n) {
    fa[i] = i;
    int x, y;
    cin >> b[i].x >> b[i].y;
  }
  double sum = 0.0;
  _for(i, 1, m) {
    int x, y;
    cin >> x >> y;
    a[i].x = x;
    a[i].y = y;
    a[i].length = get(b[x].x, b[y].x, b[x].y, b[y].y);
    sum += a[i].length;
  }
  sort(a + 1, a + 1 + m, cmp);
  _for(i, 1, m) {
    int p = find(a[i].x);
    int q = find(a[i].y);
    if (p != q) {
      sum -= a[i].length;
      fa[p] = q;
    }
  }
  printf("%.3f\\n", sum);
  return 0;
}
Problem p01341 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long LL;

int n, m;
int pa[20000];

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

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

struct edge {
  int x, y;
  double w;
  bool operator<(struct edge t) const { return (t.w - w) < 1e-6; }
} e[100000];

struct point {
  double x, y;
} p[100000];

double kruskal() {
  double res = 0;
  int cnt = 0;
  for (int i = 1; i <= m; i++) {
    int a = find(e[i].x), b = find(e[i].y);
    if (a != b) {
      pa[a] = b;
      cnt++;
      res += e[i].w;
    }
    if (cnt == n - 1)
      break;
  }
  return res;
}

int main() {
  // freopen("C:in.txt","r",stdin);
  // freopen("C:out.txt","w",stdout);
  while (~scanf("%d%d", &n, &m)) {
    memset(p, 0, sizeof(p));
    memset(e, 0, sizeof(e));

    init();
    double sum = 0;

    for (int i = 1; i <= n; i++)
      scanf("%lf%lf", &p[i].x, &p[i].y);

    for (int i = 1; i <= m; i++) {
      int tx, ty;
      scanf("%d%d", &tx, &ty);
      e[i].x = tx, e[i].y = ty;
      e[i].w = sqrt((p[tx].x - p[ty].x) * (p[tx].x - p[ty].x) +
                    (p[tx].y - p[ty].y) * (p[tx].y - p[ty].y));
      sum += e[i].w;
    }
    sort(e + 1, e + m + 1);
    printf("%.3f\\n", sum - kruskal());
  }
  return 0;
}

Error: 0

Fixed submission:

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

typedef long long LL;

int n, m;
int pa[20000];

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

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

struct edge {
  int x, y;
  double w;
  bool operator<(struct edge t) const { return (t.w - w) < 1e-6; }
} e[20000];

struct point {
  double x, y;
} p[20000];

double kruskal() {
  double res = 0;
  int cnt = 0;
  for (int i = 1; i <= m; i++) {
    int a = find(e[i].x), b = find(e[i].y);
    if (a != b) {
      pa[a] = b;
      cnt++;
      res += e[i].w;
    }
    if (cnt == n - 1)
      break;
  }
  return res;
}

int main() {
  // freopen("C:in.txt","r",stdin);
  // freopen("C:out.txt","w",stdout);
  while (~scanf("%d%d", &n, &m)) {
    memset(p, 0, sizeof(p));
    memset(e, 0, sizeof(e));

    init();
    double sum = 0;

    for (int i = 1; i <= n; i++)
      scanf("%lf%lf", &p[i].x, &p[i].y);

    for (int i = 1; i <= m; i++) {
      int tx, ty;
      scanf("%d%d", &tx, &ty);
      e[i].x = tx, e[i].y = ty;
      e[i].w = sqrt((p[tx].x - p[ty].x) * (p[tx].x - p[ty].x) +
                    (p[tx].y - p[ty].y) * (p[tx].y - p[ty].y));
      sum += e[i].w;
    }
    sort(e + 1, e + m + 1);
    printf("%.3f\\n", sum - kruskal());
  }
  return 0;
}