alexjercan/bugnet huggingface dataset:
Problem p00071 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <stdio.h>
#include <string.h>
#include <vector>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << x << endl;
using namespace std;

char s[8][9];

void barn(int x, int y) {
  if (x < 0 || y < 0 || x > 7 || y > 7)
    return;
  if (s[x][y] == '0')
    return;
  s[x][y] = '0';
  barn(x + 1, y);
  barn(x + 2, y);
  barn(x + 3, y);
  barn(x - 1, y);
  barn(x - 2, y);
  barn(x - 3, y);
  barn(x, y + 1);
  barn(x, y + 2);
  barn(x, y + 3);
  barn(x, y - 1);
  barn(x, y - 2);
  barn(x, y - 3);
}

int main() {
  int n;
  cin >> n;
  rep(i, n) {
    int x, y;
    rep(j, 8) { cin >> s[j]; }
    cin >> x >> y;
    barn(y - 1, x - 1);

    cout << "Data " << i + 1 << ':' << endl;
    rep(j, 8) { cout << s[j] << endl; }
  }
}

Error: 0

Fixed submission:

#include <iomanip>
#include <iostream>
#include <list>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

void barn(char map[][14], int i, int j) {
  map[i][j] = '0';
  range(k, 1, 4) {
    if (map[i][j + k] == '1')
      barn(map, i, i + k);
    if (map[i][j - k] == '1')
      barn(map, i, j - k);
    if (map[i + k][j] == '1')
      barn(map, i + k, j);
    if (map[i - k][j] == '1')
      barn(map, i - k, j);
  }
}

int main() {
  int n;
  char map[14][14] = {'0'};
  cin >> n;
  rep(i, n) {
    string s;
    rep(j, 8) {
      cin >> s;
      rep(k, 8) { map[j + 3][k + 3] = s[k]; }
    }
    int x, y;
    cin >> x >> y;
    x += 2;
    y += 2;
    barn(map, y, x);
    cout << "Data " << i + 1 << ":" << endl;
    range(j, 3, 11) {
      range(k, 3, 11) { cout << map[j][k]; }
      cout << endl;
    }
  }
}
Problem p00071 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int x[30][30], n, p, q;
char a;
int main() {
  cin >> n;
  for (int times = 1; times <= n; times++) {
    for (int i = 10; i < 18; i++) {
      for (int j = 10; j < 18; j++) {
        cin >> a;
        if (a == '1') {
          x[i][j] = 1;
        } else {
          x[i][j] = 0;
        }
      }
    }
    cin >> q >> p;
    x[9 + p][9 + q] = 2;
    for (int i = 0; i < 100; i++) {
      for (int j = 10; j < 18; j++) {
        for (int k = 10; k < 18; k++) {
          if (x[j][k] == 2) {
            for (int l = -3; l < 4; l++) {
              if (x[j + l][k] == 1) {
                x[j + l][k] = 2;
              }
            }
            for (int l = -3; l < 4; l++) {
              if (x[j][k + l] == 1) {
                x[j][k + l] = 2;
              }
            }
            x[j][k] = 0;
          }
        }
      }
    }
    cout << "Data " << times << ':' << endl;
    for (int i = 10; i < 18; i++) {
      for (int j = 10; j < 18; j++) {
        cout << x[i][j];
      }
      cout << endl;
    }
  }
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int x[30][30], n, p, q;
int main() {
  cin >> n;
  for (int times = 1; times <= n; times++) {
    for (int i = 10; i < 18; i++) {
      for (int j = 10; j < 18; j++) {
        cin >> x[i][j];
      }
    }
    cin >> q >> p;
    x[9 + p][9 + q] = 2;
    for (int i = 0; i < 100; i++) {
      for (int j = 10; j < 18; j++) {
        for (int k = 10; k < 18; k++) {
          if (x[j][k] == 2) {
            for (int l = -3; l < 4; l++) {
              if (x[j + l][k] == 1) {
                x[j + l][k] = 2;
              }
            }
            for (int l = -3; l < 4; l++) {
              if (x[j][k + l] == 1) {
                x[j][k + l] = 2;
              }
            }
          }
        }
      }
    }
    cout << "Data " << times << ':' << endl;
    for (int i = 10; i < 18; i++) {
      for (int j = 10; j < 18; j++) {
        cout << x[i][j];
      }
      cout << endl;
    }
  }
}
Problem p00072 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#define MAX_V 100
#define INF (1 << 21)
using namespace std;

int cost[MAX_V][MAX_V];
int mincost[MAX_V];
bool used[MAX_V];
int V;
int prim() {
  for (int i = 0; i < V; i++) {
    mincost[i] = INF;
    used[i] = false;
  }
  mincost[0] = 0;
  int 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)
      break;
    used[v] = true;
    res += mincost[v];
    for (int u = 0; u < V; u++) {
      mincost[u] = min(mincost[u], cost[v][u]);
    }
  }
  return res;
}

int main() {
  int m;
  while (1) {
    cin >> V;
    if (V == 0)
      break;
    for (int i = 0; i < V; i++) {
      for (int j = 0; j < V; j++) {
        cost[i][j] = INF;
      }
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
      int a, b, c;
      char d, e;
      cin >> a >> d >> b >> e >> c;
      cost[a][b] = c;
      cost[b][a] = c;
    }
    int t = prim();
    t = t / 100 - V + 1;
    cout << t << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#define MAX_V 100
#define INF (1 << 21)
using namespace std;

int cost[MAX_V][MAX_V];
int mincost[MAX_V];
bool used[MAX_V];
int V;
int prim() {
  for (int i = 0; i < V; i++) {
    mincost[i] = INF;
    used[i] = false;
  }
  mincost[0] = 0;
  int 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)
      break;
    used[v] = true;
    res += mincost[v];
    for (int u = 0; u < V; u++) {
      mincost[u] = min(mincost[u], cost[v][u]);
    }
  }
  return res;
}

int main() {
  int m;
  while (1) {
    cin >> V;
    if (V == 0)
      break;
    for (int i = 0; i < V; i++) {
      for (int j = 0; j < V; j++) {
        cost[i][j] = INF;
      }
    }
    cin >> m;
    for (int i = 0; i < V; i++) {
      int a, b, c;
      char d, e;
      cin >> a >> d >> b >> e >> c;
      cost[a][b] = c;
      cost[b][a] = c;
    }
    int t = prim();
    t = t / 100 - m + 1;
    cout << t << endl;
  }
}
Problem p00072 (C++) — buggy submission, verdict: Runtime Error

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

const int INF = 1000000000;
const int MAX_V = 10000;

int cost[MAX_V][MAX_V];
int mincost[MAX_V];
bool used[MAX_V];

int V;

int prim() {
  for (int i = 0; i < V; ++i) {
    mincost[i] = INF;
    used[i] = false;
  }

  mincost[0] = 0;
  int res = 0;

  while (true) {
    int v = -1;
    for (int u = 0; u < V; u++) {
      if (!used[u] && (v == -1 || mincost[u] < mincost[v]))
        v = u;
    }

    if (v == -1)
      break;
    used[v] = true;
    res += mincost[v];

    for (int u = 0; u < V; u++) {
      mincost[u] = min(mincost[u], cost[v][u]);
    }
  }
  return res;
}

int main() {
  int m;
  while (cin >> V >> m, V) {
    for (int i = 0; i < V; i++) {
      for (int j = 0; j < m; j++) {
        cost[i][j] = INF;
      }
    }
    for (int i = 0; i < m; i++) {
      char ch;
      int a, b, c;
      cin >> a >> ch >> b >> ch >> c;
      cost[a][b] = c;
      cost[b][a] = c;
    }
    int ans = prim();
    cout << (ans / 100) - (V - 1) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

const int INF = 1000000000;
const int MAX_V = 101;

int cost[MAX_V][MAX_V];
int mincost[MAX_V];
bool used[MAX_V];

int V;

int prim() {
  for (int i = 0; i < V; ++i) {
    mincost[i] = INF;
    used[i] = false;
  }

  mincost[0] = 0;
  int res = 0;

  while (true) {
    int v = -1;
    for (int u = 0; u < V; u++) {
      if (!used[u] && (v == -1 || mincost[u] < mincost[v]))
        v = u;
    }

    if (v == -1)
      break;
    used[v] = true;
    res += mincost[v];

    for (int u = 0; u < V; u++) {
      mincost[u] = min(mincost[u], cost[v][u]);
    }
  }
  return res;
}

int main() {
  int m;
  while (cin >> V >> m, V) {
    for (int i = 0; i < V; i++) {
      for (int j = 0; j < m; j++) {
        cost[i][j] = INF;
      }
    }
    for (int i = 0; i < m; i++) {
      char ch;
      int a, b, c;
      cin >> a >> ch >> b >> ch >> c;
      cost[a][b] = c;
      cost[b][a] = c;
    }
    int ans = prim();
    cout << (ans / 100) - (V - 1) << endl;
  }
  return 0;
}
Problem p00072 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)

const int maxn = 110, maxm = 5500;
#define inf 10000

int cost[maxn][maxn] = {};
int mincost[maxn] = {};
bool used[maxn] = {};
int n, m, a, b, temp;
char t;

int main() {
  while (cin >> n && n) {
    cin >> m;
    memset(cost, inf, sizeof(cost));
    memset(mincost, inf, sizeof(mincost));
    memset(used, false, sizeof(used));
    mincost[0] = 0;

    int ans = 0;
    REP(m) {
      cin >> a >> t >> b >> t >> temp;
      cost[a][b] = (temp / 100) - 1;
      cost[b][a] = cost[a][b];
    }

    while (1) {
      int minv = n;
      rep(i, n) if (!used[i] && (minv == n || mincost[i] < mincost[minv]))
          minv = i;
      if (minv == n)
        break;

      used[minv] = true;
      ans += mincost[minv];

      REP(n) mincost[i] = min(mincost[i], cost[minv][i]);
    }
    cout << ans << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)

const int maxn = 101, maxm = 5500;
#define inf 10000

int cost[maxn][maxn] = {};
int mincost[maxn] = {};
bool used[maxn] = {};
int n, m, a, b, temp;
char t;

int main() {
  while (cin >> n && n) {
    cin >> m;
    memset(cost, inf, sizeof(cost));
    memset(mincost, inf, sizeof(mincost));
    memset(used, false, sizeof(used));
    mincost[0] = 0;

    int ans = 0;
    REP(m) {
      cin >> a >> t >> b >> t >> temp;
      cost[a][b] = (temp / 100) - 1;
      cost[b][a] = cost[a][b];
    }

    while (1) {
      int minv = inf;
      rep(i, n) if (!used[i] && (mincost[minv] == inf ||
                                 mincost[i] < mincost[minv])) minv = i;
      if (minv == inf)
        break;

      used[minv] = true;
      ans += mincost[minv];

      REP(n) mincost[i] = min(mincost[i], cost[minv][i]);
    }
    cout << ans << endl;
  }

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

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

int inf = 1 << 21;
int n;

int prim_souwa(int G[500][500]) {
  int d[n], vstd[n];
  int u = 0, sum = 0;
  fill(d, d + n, inf);
  fill(vstd, vstd + n, 0);
  d[0] = 0;
  while (true) {
    int mini = inf;
    for (int i = 0; i < n; i++) {
      if (mini > d[i] && vstd[i] == 0) {
        mini = d[i];
        u = i;
      }
    }
    if (mini == inf)
      break;
    sum += mini;
    vstd[u] = 1;
    for (int i = 0; i < n; i++) {
      if (G[u][i] < d[i]) {
        d[i] = G[u][i];
      }
    }
  }
  return sum;
}

int main() {
  int m;
  int G[500][500];
  while (cin >> n, n) {
    cin >> m;
    fill(G[0], G[500], inf);
    for (int i = 0; i < m; i++) {
      int in1, in2, in3;
      scanf("%d,%d,%d", &in1, &in2, &in3);
      G[in1][in2] = in3;
      G[in2][in1] = in3;
    }
    cout << prim_souwa(G) / 100 - (n - 1) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int inf = 1 << 21;
int mst[20][20];
int n;

int prim_souwa(int G[20][20]) {
  int d[n], vstd[n];
  int u = 0, sum = 0;
  fill(d, d + n, inf);
  fill(vstd, vstd + n, 0);
  d[0] = 0;
  while (true) {
    int mini = inf;
    for (int i = 0; i < n; i++) {
      if (mini > d[i] && vstd[i] == 0) {
        mini = d[i];
        u = i;
      }
    }
    if (mini == inf)
      break;
    sum += mini;
    vstd[u] = 1;
    for (int i = 0; i < n; i++) {
      if (G[u][i] < d[i]) {
        d[i] = G[u][i];
      }
    }
  }
  return sum;
}

int main() {
  int m;
  int G[20][20];
  while (cin >> n, n) {
    cin >> m;
    fill(G[0], G[20], inf);
    for (int i = 0; i < m; i++) {
      int in1, in2, in3;
      scanf("%d,%d,%d", &in1, &in2, &in3);
      G[in1][in2] = in3;
      G[in2][in1] = in3;
    }
    cout << prim_souwa(G) / 100 - (n - 1) << endl;
  }
  return 0;
}
Problem p00072 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
#pragma warning(disable : 4996)
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INF 1000000000000000000LL
using namespace std;
long long prim(int V, vector<pair<long long, long long>> X[]) {
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      Q;
  long long dist[101], color[101];
  for (int i = 0; i < V; i++) {
    dist[i] = INF;
    color[i] = WHITE;
  }
  dist[0] = 0;
  color[0] = GRAY;
  Q.push(make_pair(0, 0));
  while (!Q.empty()) {
    pair<long long, long long> pa = Q.top();
    Q.pop();
    long long a1 = pa.first, a2 = pa.second;
    color[a2] = BLACK;
    for (int i = 0; i < X[a2].size(); i++) {
      long long to = X[a2][i].first, leng = X[a2][i].second;
      if (dist[to] > leng && color[to] < BLACK) {
        dist[to] = leng;
        Q.push(make_pair(dist[to], to));
      }
    }
  }
  long long sum = 0;
  for (int i = 0; i < V; i++) {
    sum += dist[i];
  } // 0-indexed
  return sum;
}
int n, m, u, v, w;
vector<pair<long long, long long>> g[100];
int main() {
  while (scanf("%d", &n), n) {
    scanf("%d", &m);
    for (int i = 0; i < n; i++)
      g[i].clear();
    for (int i = 0; i < m; i++) {
      scanf("%d,%d,%d", &u, &v, &w);
      g[u].push_back(make_pair((long long)(v), (long long)(w / 100 - 1)));
      g[v].push_back(make_pair((long long)(u), (long long)(w / 100 - 1)));
    }
    cout << prim(n, g) << endl;
  }
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INF 1000000000000000000LL
using namespace std;
long long prim(int V, vector<pair<long long, long long>> X[]) {
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      Q;
  ;
  long long dist[100], color[100];
  for (int i = 0; i < V; i++) {
    dist[i] = INF;
    color[i] = WHITE;
  }
  dist[0] = 0;
  color[0] = GRAY;
  Q.push(make_pair(0, 0));
  while (!Q.empty()) {
    pair<long long, long long> pa = Q.top();
    Q.pop();
    long long a1 = pa.first, a2 = pa.second;
    color[a2] = BLACK;
    for (int i = 0; i < X[a2].size(); i++) {
      long long to = X[a2][i].first, leng = X[a2][i].second;
      if (dist[to] > leng && color[to] < BLACK) {
        dist[to] = leng;
        Q.push(make_pair(dist[to], to));
      }
    }
  }
  long long sum = 0;
  for (int i = 0; i < V; i++) {
    sum += dist[i];
  } // 0-indexed
  return sum;
}
int n, m, u, v, w;
vector<pair<long long, long long>> g[100];
int main() {
  while (cin >> n >> m) {
    for (int i = 0; i < n; i++)
      g[i].clear();
    for (int i = 0; i < m; i++) {
      scanf("%d,%d,%d", u, v, w);
      g[u].push_back(make_pair(v, w / 100 - 1));
      g[v].push_back(make_pair(u, w / 100 - 1));
    }
    cout << prim(n, g) << endl;
  }
}
Problem p00072 (C++) — buggy submission, verdict: Runtime Error

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

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

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

const int MAX_N = 101;
const int MAX_E = 10000;
int par[MAX_N];
int r[MAX_N];

void init(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    r[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 (r[x] < r[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (r[x] == r[y])
      r[x]++;
  }
}

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

edge es[MAX_E];
int V, E;

int kruskal() {
  sort(es, es + E, comp);
  init(V);
  int res = 0;
  for (int i = 0; i < E; i++) {
    edge e = es[i];
    if (!same(e.u, e.v)) {
      unite(e.u, e.v);
      res += e.cost;
    }
  }
  return res;
}

int main() {
  while (cin >> V >> E, V) {

    for (int i = 0; i < E; i++) {
      char ch;
      cin >> es[i].u >> ch >> es[i].v >> ch >> es[i].cost;
    }

    int ans = kruskal();
    cout << ((ans / 100) - (V - 1)) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

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

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

const int MAX_N = 101;
const int MAX_E = 150;
int par[MAX_N];
int r[MAX_N];

void init(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    r[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 (r[x] < r[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (r[x] == r[y])
      r[x]++;
  }
}

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

edge es[MAX_E];
int V, E;

int kruskal() {
  sort(es, es + E, comp);
  init(V);
  int res = 0;
  for (int i = 0; i < E; i++) {
    edge e = es[i];
    if (!same(e.u, e.v)) {
      unite(e.u, e.v);
      res += e.cost;
    }
  }
  return res;
}

int main() {
  while (cin >> V >> E, V) {

    for (int i = 0; i < E; i++) {
      char ch;
      cin >> es[i].u >> ch >> es[i].v >> ch >> es[i].cost;
    }

    int ans = kruskal();
    cout << ((ans / 100) - (V - 1)) << endl;
  }
  return 0;
}
Problem p00072 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_str(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef long long ll;
const int INF = 1 << 28;

int main() {
  int dist[101][101], mincost[101];
  bool used[101];

  int n, m;
  int a, b, c;

  while (cin >> n, n) {
    int total = 0;
    cin >> m;

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        dist[i][j] = INF;

        if (i == j) {
          dist[i][j] = 0;
        }
      }
      used[i] = false;
      mincost[i] = INF;
    }
    for (int i = 0; i < m; i++) {
      scanf("%d%*c%d%*c%d", &a, &b, &c);
      c /= 100;
      c -= 1;
      dist[a][b] = c;
      dist[b][a] = c;
    }

    mincost[0] = 0;

    while (1) {
      int v = -1;
      for (int i = 0; i < n; i++) {
        if (!used[i] && (v == -1 || mincost[i] < mincost[v]))
          v = i;
      }
      if (v == -1) {
        break;
      }

      used[v] = true;
      total += mincost[v];

      for (int i = 0; i < n; i++) {
        mincost[i] = min(mincost[i], dist[v][i]);
      }
    }

    cout << total << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_str(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef long long ll;
const int INF = 1 << 28;

int main() {
  int dist[101][101], mincost[101];
  bool used[101];

  int n, m;
  int a, b, c;

  while (cin >> n, n) {
    int total = 0;

    cin >> m;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        dist[i][j] = INF;

        if (i == j) {
          dist[i][j] = 0;
        }
      }
      used[i] = false;
      mincost[i] = INF;
    }
    for (int i = 0; i < n; i++) {
      scanf("%d%*c%d%*c%d", &a, &b, &c);
      c /= 100;
      c -= 1;
      dist[a][b] = c;
      dist[b][a] = c;
    }

    mincost[0] = 0;

    while (1) {
      int v = -1;
      for (int i = 0; i < n; i++) {
        if (!used[i] && (v == -1 || mincost[i] < mincost[v]))
          v = i;
      }
      if (v == -1) {
        break;
      }

      used[v] = true;
      total += mincost[v];

      for (int i = 0; i < n; i++) {
        mincost[i] = min(mincost[i], dist[v][i]);
      }
    }

    cout << total << endl;
  }
}
Problem p00072 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
const int N = 100000;
int par[N];
int rank[N];

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

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

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

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

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

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

edge es[1000000];
int V, E;

int kruskal() {
  std::sort(es, es + E, comp);
  init(V);
  int res = 0;
  for (int i = 0; i < E; ++i) {
    edge e = es[i];
    if (!same(e.u, e.v)) {
      unite(e.u, e.v);
      res += e.cost;
    }
  }
  return res;
}

int main() {
  while (1) {
    scanf("%d", &V);
    if (V == 0)
      break;
    scanf("%d", &E);
    for (int i = 0; i < E; ++i) {
      int a, b, c;
      scanf("%d,%d,%d", &a, &b, &c);
      es[i].u = a, es[i].v = b, es[i].cost = c;
    }
    int ans = kruskal();
    printf("%d\\n", ans / 100 - V + 1);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Edge {
  int from, to, cost;
};

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

const int N = 100;
vector<Edge> e;

int par[N];
int rank_[N];

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 (rank_[x] < rank_[y])
    par[x] = y;
  else {
    par[y] = x;
    if (rank_[x] == rank_[y])
      rank_[x]++;
  }
}

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

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

  while (1) {
    int n, m;
    cin >> n;
    if (n == 0)
      break;
    cin >> m;

    string str;
    for (int i = 0; i != n; ++i) {
      int abc[3] = {};
      cin >> str;
      int count = 0;
      for (size_t i = 0; i != str.size(); ++i) {
        if (str[i] == ',')
          count++;
        else {
          abc[count] *= 10;
          abc[count] += str[i] - '0';
        }
      }
      /*cout << abc[0] << endl;
      cout << abc[1] << endl;
      cout << abc[2] << endl;*/
      e.push_back(Edge{abc[0], abc[1], abc[2] / 100 - 1});
    }

    for (int i = 0; i != n; ++i) {
      par[i] = i;
      rank_[i] = 0;
    }

    sort(e.begin(), e.end(), comp);

    int ans = 0;
    for (int i = 0; i != n; ++i) {
      if (!same(e[i].from, e[i].to)) {
        unite(e[i].from, e[i].to);
        ans += e[i].cost;
      }
    }

    cout << ans << endl;
  }

  return 0;
}