Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

const double PI = 3.141592653589793238463;
const int INF = 1000000007;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

M warshallFloyd(int n, int m, const V &as, const V &bs, const V &cs) {
  M dss(n, V(n, INF));
  for (int i = 0; i < n; i++) {
    dss[i][i] = 0;
  }
  for (int i = 0; i < m; i++) {
    dss[as[i] - 1][bs[i] - 1] = cs[i];
    dss[bs[i] - 1][as[i] - 1] = cs[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        dss[j][k] = min(dss[j][k], dss[j][i] + dss[i][k]);
      }
    }
  }
  return dss;
}

int solve(int n, int m, V &as, V &bs, V &cs) {
  const M &dss = warshallFloyd(n, m, as, bs, cs);
  V us(m, false);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < m; k++) {
        if (dss[i][j] == dss[i][as[k] - 1] + cs[k] + dss[bs[k] - 1][j]) {
          us[k] = true;
        }
      }
    }
  }
  return count(us.begin(), us.end(), false);
}

int main(int argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, m;
  cin >> n >> m;
  V as(m), bs(m), cs(m);
  for (int i = 0; i < n; i++) {
    cin >> as[i] >> bs[i] >> cs[i];
  }

  cout << solve(n, m, as, bs, cs) << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

const double PI = 3.141592653589793238463;
const int INF = 1000000007;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

M warshallFloyd(int n, int m, const V &as, const V &bs, const V &cs) {
  M dss(n, V(n, INF));
  for (int i = 0; i < n; i++) {
    dss[i][i] = 0;
  }
  for (int i = 0; i < m; i++) {
    dss[as[i] - 1][bs[i] - 1] = cs[i];
    dss[bs[i] - 1][as[i] - 1] = cs[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        dss[j][k] = min(dss[j][k], dss[j][i] + dss[i][k]);
      }
    }
  }
  return dss;
}

int solve(int n, int m, V &as, V &bs, V &cs) {
  const M &dss = warshallFloyd(n, m, as, bs, cs);
  V us(m, false);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < m; k++) {
        if (dss[i][j] == dss[i][as[k] - 1] + cs[k] + dss[bs[k] - 1][j]) {
          us[k] = true;
        }
      }
    }
  }
  return count(us.begin(), us.end(), false);
}

int main(int argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, m;
  cin >> n >> m;
  V as(m), bs(m), cs(m);
  for (int i = 0; i < m; i++) {
    cin >> as[i] >> bs[i] >> cs[i];
  }

  cout << solve(n, m, as, bs, cs) << endl;

  return 0;
}