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

#include <algorithm>
#include <iostream>
#include <vector>

constexpr int MAX_N = 100;

struct edge {
  int from_, to_, cost_;
  edge() = default;
  edge(int from, int to, int cost) : from_(from), to_(to), cost_(cost) {}
  bool operator<(const edge &rhs) const {
    return (cost_ == rhs.cost_) ? to_ < rhs.to_ : cost_ < rhs.cost_;
  }
};

int n, m;
std::vector<edge> edges;

class Union {
  int par[MAX_N], rank[MAX_N];

public:
  Union() {
    for (int i = 0; i < n; ++i) {
      par[i] = i;
      rank[i] = 0;
    }
  }
  int find(int x) {
    if (x == par[x])
      return x;
    return par[x] = find(par[x]);
  }
  bool same(int x, int y) { return find(x) == find(y); }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return;
    if (rank[x] < rank[y])
      std::swap(x, y);
    par[y] = x;
    rank[x] += rank[y];
  }
};

int main() {
  while (1) {
    std::cin >> n;
    if (!n)
      break;
    std::cin >> m;
    Union uni;
    edges.clear();
    int a, b, d;
    char ch;
    for (int i = 0; i < m; ++i) {
      std::cin >> a >> ch >> b >> ch >> d;
      d /= 100;
      --d;
      edges.push_back(edge(a, b, d));
    }

    std::sort(edges.begin(), edges.end());

    long long int ans = 0;
    for (int i = 0; i < edges.size(); ++i) {
      if (!uni.same(edges[i].from_, edges[i].to_)) {
        uni.unite(edges[i].from_, edges[i].to_);
        ans += edges[i].cost_;
      }
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

constexpr int MAX_N = 100;

struct edge {
  int from_, to_, cost_;
  edge() = default;
  edge(int from, int to, int cost) : from_(from), to_(to), cost_(cost) {}
  bool operator<(const edge &rhs) const {
    return (cost_ == rhs.cost_) ? to_ < rhs.to_ : cost_ < rhs.cost_;
  }
};

int n, m;
std::vector<edge> edges;

class Union {
  int par[MAX_N], rank[MAX_N];

public:
  Union() {
    for (int i = 0; i < n; ++i) {
      par[i] = i;
      rank[i] = 0;
    }
  }
  int find(int x) {
    if (x == par[x])
      return x;
    par[x] = find(par[x]);
  }
  bool same(int x, int y) { return find(x) == find(y); }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return;
    if (rank[x] < rank[y])
      std::swap(x, y);
    par[y] = x;
    rank[x] += rank[y];
  }
};

int main() {
  while (1) {
    std::cin >> n;
    if (!n)
      break;
    std::cin >> m;
    Union uni;
    edges.clear();
    int a, b, d;
    char ch;
    for (int i = 0; i < m; ++i) {
      std::cin >> a >> ch >> b >> ch >> d;
      d /= 100;
      --d;
      edges.push_back(edge(a, b, d));
    }

    std::sort(edges.begin(), edges.end());

    long long int ans = 0;
    for (int i = 0; i < edges.size(); ++i) {
      if (!uni.same(edges[i].from_, edges[i].to_)) {
        uni.unite(edges[i].from_, edges[i].to_);
        ans += edges[i].cost_;
      }
    }
    std::cout << ans << std::endl;
  }
  return 0;
}
Problem p00072 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <utility>
#include <vector>

using namespace std;

#define NMAX 100
#define NOT -1

struct mini {
  int fr, to, cost;
};

int main() {

  int n, m;
  int a, b, d;
  char gav;
  int e[NMAX][NMAX];
  bool use[NMAX];
  int cost;
  mini min;

  while (1) {

    cin >> n;
    if (n == 0)
      break;
    cin >> m;

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        e[i][j] = NOT;
      }
    }

    for (int i = 0; i < m; i++) {
      cin >> a >> gav >> b >> gav >> d;
      e[a][b] = d;
      e[b][a] = d;
    }

    for (int i = 0; i < n; i++)
      use[i] = false;
    use[0] = true;
    cost = 0;

    while (1) {
      min.fr = NOT, min.to = NOT, min.cost = NOT;
      for (int i = 0; i < n; i++) {
        if (use[i] == true) {
          for (int j = 0; j < n; j++) {
            if (use[j] == false) {
              if (e[i][j] != NOT) {
                if (min.fr == NOT || min.cost > e[i][j])
                  min.fr = i, min.to = j, min.cost = e[i][j];
              }
            }
          }
        }
      }
      if (min.fr == NOT)
        break;
      use[min.to] = true;
      cost += (min.cost) / 100 - 1;
    }
    cout << cost << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <utility>
#include <vector>

using namespace std;

#define NMAX 100 * 2
#define NOT -1

struct mini {
  int fr, to, cost;
};

int main() {

  int n, m;
  int a, b, d;
  char gav;
  int e[NMAX][NMAX];
  bool use[NMAX];
  int cost;
  mini min;

  while (1) {

    cin >> n;
    if (n == 0)
      break;
    cin >> m;

    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        e[i][j] = NOT;
      }
    }

    for (int i = 0; i < m; i++) {
      cin >> a >> gav >> b >> gav >> d;
      e[a][b] = d;
      e[b][a] = d;
    }

    for (int i = 0; i < m; i++)
      use[i] = false;
    use[0] = true;
    cost = 0;

    while (1) {
      min.fr = NOT, min.to = NOT, min.cost = NOT;
      for (int i = 0; i < m; i++) {
        if (use[i] == true) {
          for (int j = 0; j < m; j++) {
            if (use[j] == false) {
              if (e[i][j] != NOT) {
                if (min.fr == NOT || min.cost > e[i][j])
                  min.fr = i, min.to = j, min.cost = e[i][j];
              }
            }
          }
        }
      }
      if (min.fr == NOT)
        break;
      use[min.to] = true;
      cost += (min.cost) / 100 - 1;
    }
    cout << cost << endl;
  }
}
Problem p00072 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

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

typedef vector<int> vi;
typedef pair<int, int> pii;

struct Edge {
  int src, dst, cost;
  Edge(int s, int d, int c) : src(s), dst(d), cost(c) {}
  Edge() {}
  bool operator<(const Edge &e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

Edges prim(const Graph &g) {
  Edges T;
  vector<int> visited(g.size(), 0);
  visited[0] = 1;

  priority_queue<Edge> Q;
  rep(i, g[0].size()) Q.push(g[0][i]);

  while (!Q.empty()) {
    Edge e = Q.top();
    Q.pop();
    if (visited[e.dst])
      continue;
    T.push_back(e);
    visited[e.dst] = 1;
    rep(i, g[e.dst].size()) {
      if (!visited[g[e.dst][i].dst])
        Q.push(g[e.dst][i]);
    }
  }
  return T;
}

int main() {
  int n, m;
  while (scanf("%d", &n), n) {
    scanf("%d", &m);
    Graph g(n);
    rep(i, m) {
      int a, b, d;
      scanf("%d,%d,%d", &a, &b, &d);
      g[a].push_back(Edge(a, b, d));
      g[b].push_back(Edge(b, a, d));
    }
    Edges t = prim(g);
    int ans = 0;
    rep(i, t.size()) ans += t[i].cost / 100 - 1;
    printf("%d\\n", ans);
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

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

typedef vector<int> vi;
typedef pair<int, int> pii;

struct Edge {
  int src, dst, cost;
  Edge(int s, int d, int c) : src(s), dst(d), cost(c) {}
  Edge() {}
  bool operator<(const Edge &e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

Edges prim(const Graph &g) {
  Edges T;
  vector<int> visited(g.size(), 0);
  visited[0] = 1;

  priority_queue<Edge> Q;
  rep(i, g[0].size()) Q.push(g[0][i]);

  while (!Q.empty()) {
    Edge e = Q.top();
    Q.pop();
    if (visited[e.dst])
      continue;
    T.push_back(e);
    visited[e.dst] = 1;
    rep(i, g[e.dst].size()) {
      if (!visited[g[e.dst][i].dst])
        Q.push(g[e.dst][i]);
    }
  }
  return T;
}

int main() {
  int n, m;
  while (scanf("%d", &n), n) {
    scanf("%d", &m);
    Graph g(n);
    rep(i, n) {
      int a, b, d;
      scanf("%d,%d,%d", &a, &b, &d);
      g[a].push_back(Edge(a, b, d));
      g[b].push_back(Edge(b, a, d));
    }
    Edges t = prim(g);
    int ans = 0;
    rep(i, t.size()) ans += t[i].cost / 100 - 1;
    printf("%d\\n", ans);
  }

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

#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#define INF 1e8

using namespace std;
int main() {
  int n, m;
  while (cin >> n, n) {
    cin >> m;
    vector<vector<int>> g(n);
    for (int i = 0; i < n; ++i) {
      g[i].reserve(n);
      for (int j = 0; j < n; ++j)
        g[i][j] = INF;
    }
    for (int i = 0, a, b, d; i < m; ++i) {
      scanf("%d,%d,%d", &a, &b, &d);
      g[a][b] = d / 100 - 1;
      g[b][a] = d / 100 - 1;
    }
    int ans = 0;
    set<int> v;
    v.insert(0);
    while (v.size() != n) {
      int min_cost = INF, to = 0;
      for (set<int>::iterator vit = v.begin(); vit != v.end(); ++vit) {
        for (int i = 0; i < n; ++i) {
          if (v.find(i) == v.end() && g[*vit][i] < min_cost) {
            to = i;
            min_cost = g[*vit][i];
          }
        }
      }
      ans += min_cost;
      v.insert(to);
    }
    cout << ans << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#define INF 1e8

using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    vector<vector<int>> g(n);
    for (int i = 0; i < n; ++i) {
      g[i].reserve(n);
      for (int j = 0; j < n; ++j)
        g[i][j] = INF;
    }
    for (int i = 0, a, b, d; i < m; ++i) {
      scanf("%d,%d,%d", &a, &b, &d);
      g[a][b] = d / 100 - 1;
      g[b][a] = d / 100 - 1;
    }
    int ans = 0;
    set<int> v;
    v.insert(0);
    while (v.size() != n) {
      int min_cost = INF, to;
      for (set<int>::iterator vit = v.begin(); vit != v.end(); ++vit) {
        for (int i = 0; i < n; ++i) {
          if (v.find(i) == v.end() && g[*vit][i] < min_cost) {
            to = i;
            min_cost = g[*vit][i];
          }
        }
      }
      ans += min_cost;
      v.insert(to);
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00072 (C++) — buggy submission, verdict: Runtime Error

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

#define MAX_V 111
#define INF (1 << 21)

int cost[MAX_V][MAX_V] = {{0}};
int mincost[MAX_V] = {};
bool used[MAX_V] = {};
int V;

int prim(void);
int min(int a, int b);

int main() {
  int m;

  scanf("%d", &V);

  while (1) {
    if (V == 0)
      break;
    scanf("%d", &m);

    for (int i = 0; i < V; i++) {
      for (int j = 0; j < V; j++) {
        cost[i][j] = INF;
      }
    }

    for (int i = 0; i < m; i++) {
      int a, b, c;
      scanf("%d,%d,%d", &a, &b, &c);
      cost[a][b] = c / 100 - 1;
      cost[b][a] = c / 100 - 1;
    }

    printf("%d\\n", prim());

    scanf("%d", &V);
  }

  return 0;
}

int min(int a, int b) {
  if (a > b)
    return b;
  return a;
}

int prim(void) {
  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++) {
      // if(cost[v][u]==0);
      // else{
      mincost[u] = min(mincost[u], cost[v][u]);
      //     }
    }
  }
  return res;
}

Error: 0

Fixed submission:

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

#define MAX_V 111
#define INF (1 << 21)

int cost[MAX_V][MAX_V] = {{0}};
int mincost[MAX_V] = {};
bool used[MAX_V] = {};
int V;

int prim(void);
int min(int a, int b);

int main() {
  int m;

  scanf("%d", &V);

  while (1) {
    if (V == 0)
      break;
    scanf("%d", &m);

    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        cost[i][j] = INF;
      }
    }

    for (int i = 0; i < m; i++) {
      int a, b, c;
      scanf("%d,%d,%d", &a, &b, &c);
      cost[a][b] = c / 100 - 1;
      cost[b][a] = c / 100 - 1;
    }

    printf("%d\\n", prim());

    scanf("%d", &V);
  }

  return 0;
}

int min(int a, int b) {
  if (a > b)
    return b;
  return a;
}

int prim(void) {
  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++) {
      // if(cost[v][u]==0);
      // else{
      mincost[u] = min(mincost[u], cost[v][u]);
      //     }
    }
  }
  return res;
}
Problem p00072 (C++) — buggy submission, verdict: Runtime Error

// kruskal tree
#include <algorithm>
#include <cstdio>
using namespace std;
#define M 99999
int parent[M], a[M], b[M];
pair<int, 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() {
  int i, s, n, m;
  for (; scanf("%d%d", &n, &m) > 1; printf("%d\\n", s / 100 - n + 1)) {
    for (i = 0; i < m; i++)
      scanf("%d,%d,%d", a + i, b + i, &node[i].first), node[i].second = i;
    sort(node, node + m);
    for (i = 0; i < n; i++)
      parent[i] = i;
    for (s = i = 0; i < m; i++)
      if (unite(a[node[i].second], b[node[i].second]))
        s += node[i].first;
  }
}

Error: 0

Fixed submission:

// kruskal tree
#include <algorithm>
#include <cstdio>
using namespace std;
#define M 999
int parent[M], a[M], b[M];
pair<int, 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() {
  int i, s, n, m;
  for (; scanf("%d%d", &n, &m) > 1; printf("%d\\n", s / 100 - n + 1)) {
    for (i = 0; i < m; i++)
      scanf("%d,%d,%d", a + i, b + i, &node[i].first), node[i].second = i;
    sort(node, node + m);
    for (i = 0; i < n; i++)
      parent[i] = i;
    for (s = i = 0; i < m; i++)
      if (unite(a[node[i].second], b[node[i].second]))
        s += node[i].first;
  }
}
Problem p00072 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define pb push_back
struct EDGE {
  int to, cost;
  EDGE(int a, int b) {
    to = a;
    cost = b;
  }
  bool operator<(const EDGE &t) const { return cost > t.cost; }
};
vector<EDGE> v[100];
bool f[100];
int search() {
  int res = 0;
  priority_queue<EDGE> que;
  que.push(EDGE(0, 0));
  while (!que.empty()) {
    EDGE e = que.top();
    que.pop();
    if (f[e.to])
      continue;
    f[e.to] = true;
    res += e.cost;
    rep(i, v[e.to].size()) {
      if (!f[v[e.to][i].to]) {
        que.push(v[e.to][i]);
      }
    }
  }
  return res;
}

int main() {
  int n, m;
  while (scanf("%d", &n), n) {
    scanf("%d", &m);
    rep(i, m) {
      int a, b, c;
      scanf("%d,%d,%d", &a, &b, &c);
      c = c / 100 - 1;
      v[a].pb(EDGE(b, c));
      v[b].pb(EDGE(a, c));
    }
    printf("%d\\n", search());
    memset(f, false, sizeof(f));
    rep(i, n) v[i].clear();
  }
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define pb push_back
struct EDGE {
  int to, cost;
  EDGE(int a, int b) {
    to = a;
    to = b;
  }
  bool operator<(const EDGE &t) const { return cost > t.cost; }
};
vector<EDGE> v[100];
bool f[100];
int search() {
  int res = 0;
  priority_queue<EDGE> que;
  que.push(EDGE(0, 0));
  while (!que.empty()) {
    EDGE e = que.top();
    que.pop();
    if (f[e.to])
      continue;
    f[e.to] = true;
    res += e.cost;
    /*
            rep(i, v[e.to].size()){
                if (!f[v[e.to][i].to]){
                    que.push(v[e.to][i]);
                }
            }
    */
  }
  return res;
}

int main() {
  int n, m;
  while (scanf("%d", &n), n) {
    scanf("%d", &m);
    rep(i, m) {
      int a, b, c;
      scanf("%d%d%d", &a, &b, &c);
      c = c / 100 - 1;
      v[a].pb(EDGE(b, c));
      v[b].pb(EDGE(a, c));
    }
    printf("%d\\n", search());
    memset(f, false, sizeof(f));
    rep(i, n) v[i].clear();
  }
  return 0;
}
Problem p00072 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define INF 999999999

#ifdef Debug
#define dump(x) cerr << #x << " = " << (x) << endl
#else
#define dump(x)
#endif

bool used[101];
int mincost[101];
int edge[101][101];

int main() {
  int n, m;
  while (cin >> n) {
    if (n == 0)
      break;
    rep(i, 101) rep(j, 101) edge[i][j] = INF;
    cin >> m;
    rep(i, m) {
      int a, b, c;
      char ch;
      cin >> a >> ch >> b >> ch >> c;
      edge[a][b] = edge[b][a] = c / 100 - 1;
    }
    rep(i, n) {
      mincost[i] = INF;
      used[i] = false;
    }
    mincost[0] = 0;
    int res = 0;

    while (1) {
      int v = -1;
      rep(u, n) {
        if (used[u] == false && (v == -1 || mincost[u] < mincost[v]))
          v = u;
      }
      if (v == -1)
        break;
      used[v] = true;
      res += mincost[v];

      rep(u, n) { mincost[u] = min(mincost[u], edge[v][u]); }
    }
    cout << res << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define INF 999999999

#ifdef Debug
#define dump(x) cerr << #x << " = " << (x) << endl
#else
#define dump(x)
#endif

bool used[5000];
int mincost[5000];
int edge[1000][1000];

int main() {
  int n, m;
  while (cin >> n) {
    if (n == 0)
      break;
    rep(i, 200) rep(j, 200) edge[i][j] = INF;
    cin >> m;
    rep(i, m) {
      int a, b, c;
      char ch;
      cin >> a >> ch >> b >> ch >> c;
      edge[a][b] = edge[b][a] = max(0, (int)(c / 100) - 1);
    }
    rep(i, m) {
      mincost[i] = INF;
      used[i] = false;
    }
    mincost[0] = 0;
    int res = 0;

    while (1) {
      int v = -1;
      rep(u, m) {
        if (used[u] == false && (v == -1 || mincost[u] < mincost[v]))
          v = u;
      }
      if (v == -1)
        break;
      used[v] = true;
      res += mincost[v];

      rep(u, m) { mincost[u] = min(mincost[u], edge[v][u]); }
    }
    cout << res << endl;
  }
  return 0;
}
Problem p00072 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <array>
#include <cstdlib>
#include <iostream>

using namespace std;

constexpr int MAX_N = 100;
constexpr int MAX_M = MAX_N * MAX_N;
int par[MAX_N];
int myrank[MAX_N];
int n, m;

struct edge {
  int a, b, d;

  bool operator<(const edge &r) { return d < r.d; }
};

array<edge, MAX_M> e;

// Union Find Tree?????????????????????
//????????¶?????§??????????????????????????§???
//?????¨??????????´???????????????????
void init() {
  for (int i = 0; i < MAX_N; i++) {
    par[i] = i;
    myrank[i] = 0;
  }
}

// x?????????????´?????±??????????????????£??¨????????????
int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}

// x,y????±?????????????????????¨??????
bool unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y)
    return false;

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

  return true;
}

int main() {
  int count, t;

  while (cin >> n, n) {
    cin >> m;
    init();

    t = 0;
    for (int i = 0; i < m; i++)
      scanf("%d,%d,%d", &(e[i].a), &(e[i].b), &(e[i].d));

    sort(e.begin(), e.begin() + m);
    for (int i = 0; i < m; ++i) {
      if (unite(e[i].a, e[i].b))
        t += e[i].d - 100;
    }
    cout << t / 100 << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <array>
#include <cstdlib>
#include <iostream>

using namespace std;

constexpr int MAX_N = 100;
constexpr int MAX_M = MAX_N * MAX_N;
int par[MAX_N];
int myrank[MAX_N];
int n, m;

struct edge {
  int a, b, d;

  bool operator<(const edge &r) { return d < r.d; }
};
array<edge, MAX_M> e;

// Union Find Tree?????????????????????
//????????¶?????§??????????????????????????§???
//?????¨??????????´???????????????????
void init() {
  for (int i = 0; i < MAX_N; i++) {
    par[i] = i;
    myrank[i] = 0;
  }
}

// x?????????????´?????±??????????????????£??¨????????????
int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}

// x,y????±?????????????????????¨??????
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) {
    return;
  }
  if (myrank[x] < myrank[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (myrank[x] == myrank[y])
      myrank[x]++;
  }
}

// x,y????±?????????????????????????????????????
int same(int x, int y) { return find(x) == find(y); }

int main() {
  int count, t;

  while (cin >> n, n) {
    cin >> m;
    init();

    t = 0;
    count = 0;
    for (int i = 0; i < m; i++) {
      scanf("%d,%d,%d", &(e[i].a), &(e[i].b), &(e[i].d));
    }

    sort(e.begin(), e.begin() + n);
    while (count != n - 1) {
      for (int i = 0; i < n; ++i) {
        if (same(e[i].a, e[i].b) != 1) {
          count++;
          t = t + (int)e[i].d / 100 - 1;
          unite(e[i].a, e[i].b);
        }
      }
      cout << t << endl;
    }
  }

  return 0;
}