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 FOR(i, s, n) for (int i = s; i <= (int)n; ++i)
#define per(i, n) for (int i = n; i > 0; i--)
#define ROF(i, s, n) for (int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\\n"
#define MP make_pair
#define PB push_back
#define EACH(i, n)                                                             \\
  for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define CLR(a) memset((a), 0, sizeof(a))
#define NCLR(a) memset((a), -1, sizeof(a))
#define int long long
static const int INF = 1ll << 60ll;
static const int dx[] = {-1, 0, 1, 0};
static const int dy[] = {0, -1, 0, 1};
int n, m;
int ans;
int cost[150];
int used[150];
int V[150][150];

int prim() {
  int res = 0;
  cost[0] = 0;
  while (1) {
    int v = -1;
    rep(i, n) {
      if (used[i] != 1 && v == -1)
        v = i;
      else if (used[i] != 1 && cost[i] < cost[v])
        v = i;
    }
    if (v == -1)
      break;
    used[v] = 1;
    res += cost[v];
    rep(i, n) { cost[i] = min(cost[i], V[v][i]); }
  }
  return res;
}

signed main() {
  while (1) {
    rep(i, 150) {
      used[i] = 0;
      cost[i] = INF;
    }
    rep(i, 150) rep(j, 150) V[i][j] = INF;
    cin >> n;
    if (n == 0)
      break;
    cin >> m;
    rep(i, m) {
      int x, y, z;
      char c;
      cin >> x >> c >> y >> c >> z;
      V[x][y] = z / 100 - 1;
      V[y][x] = z / 100 - 1;
    }
    cout << prim() << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, s, n) for (int i = s; i <= (int)n; ++i)
#define per(i, n) for (int i = n; i > 0; i--)
#define ROF(i, s, n) for (int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\\n"
#define MP make_pair
#define PB push_back
#define EACH(i, n)                                                             \\
  for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define CLR(a) memset((a), 0, sizeof(a))
#define NCLR(a) memset((a), -1, sizeof(a))
#define int long long
static const int dx[] = {-1, 0, 1, 0};
static const int dy[] = {0, -1, 0, 1};
typedef pair<int, pair<int, int>> PII;
int n, m;
int ans;
int E[150];
PII V[150];

signed main() {
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    cin >> m;
    rep(i, m) {
      int x, y, z;
      char c;
      cin >> x >> c >> y >> c >> z;
      V[i].first = z;
      V[i].second.first = x;
      V[i].second.second = y;
    }
    sort(V, V + m);
    rep(i, m) {
      if (E[V[i].second.first] == 1 && E[V[i].second.second] == 1)
        continue;
      ans += V[i].first - 100;
      E[V[i].second.first] = 1;
      E[V[i].second.second] = 1;
    }
    cout << ans / 100 << endl;
    ans = 0;
    rep(i, n) E[i] = 0;
    rep(i, m) {
      V[i].first = 0;
      V[i].second.first = 0;
      V[i].second.second = 0;
    }
  }
  return 0;
}