Problem p00072 (C++) — buggy submission, verdict: Runtime Error

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

#pragma warning(disable : 4996)

#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INF 114514

int x[1000][1000];
int color[10000];
int MIN[10000];
int sum;
int sum_min = INF;

int main() {
  while (true) {
    sum_min = INF;
    sum = 0;
    memset(x, 0, sizeof(x));
    memset(color, 0, sizeof(color));
    memset(MIN, 0, sizeof(MIN));
    int n, a, b, c, m, e, f, g;
    cin >> n;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        x[i][j] = -1;
      }
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
      scanf("%d,%d,%d", &e, &f, &g);
      x[e][f] = g / 100 - 1;
      x[f][e] = g / 100 - 1;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        MIN[j] = INF;
        color[j] = WHITE;
      }
      b = INF;
      a = n;
      color[i] = GRAY;
      MIN[i] = 0;
      while (a != 0) {
        b = INF;
        for (int j = 0; j < n; j++) {
          if (color[j] == GRAY) {
            if (b > MIN[j]) {
              b = MIN[j];
              c = j;
            }
          }
        }
        color[c] = BLACK;
        a -= 1;
        for (int k = 0; k < n; k++) {
          if (color[k] != BLACK && x[c][k] != -1) {
            color[k] = GRAY;
            MIN[k] = min(x[c][k], MIN[k]);
          }
        }
      }
      sum = 0;
      for (int j = 0; j < n; j++) {
        sum += MIN[j];
      }
      sum_min = min(sum_min, sum);
    }
    cout << sum_min << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

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

#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INF 1145141919810

int x[1000][1000];
int color[10000];
int MIN[10000];
int sum;
int sum_min = INF;

int main() {
  while (true) {
    memset(x, 0, sizeof(x));
    memset(color, 0, sizeof(color));
    memset(MIN, 0, sizeof(MIN));
    int n, a, b, c, m, e, f, g;
    cin >> n;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        x[i][j] = -1;
      }
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
      scanf("%d,%d,%d", e, f, g);
      x[e][f] = g;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        MIN[j] = INF;
        color[j] = WHITE;
      }
      b = INF;
      a = n;
      color[i] = GRAY;
      MIN[i] = 0;
      while (a != 0) {
        b = INF;
        for (int j = 0; j < n; j++) {
          if (color[j] == GRAY) {
            if (b > MIN[j]) {
              b = MIN[j];
              c = j;
            }
          }
        }
        color[c] = BLACK;
        a -= 1;
        for (int k = 0; k < n; k++) {
          if (color[k] != BLACK && x[c][k] != -1) {
            color[k] = GRAY;
            MIN[k] = min(x[c][k], MIN[k]);
          }
        }
      }
      sum = 0;
      for (int j = 0; j < n; j++) {
        sum += MIN[j];
      }
      sum_min = min(sum_min, sum);
    }
    cout << sum_min / 100 << endl;
  }
  return 0;
}