Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>
// https://qiita.com/ofutonfuton/items/92b1a6f4a7775f00b6ae

using namespace std;
typedef long long ll;
std::unordered_map<ll, std::vector<pair<pair<ll, ll>, ll>>> connection;
ll N, M;
int result = 0;

int main() {
  cin >> N >> M;
  ll *a = new ll[N];
  ll *b = new ll[N];
  ll *c = new ll[N];
  bool *result = new bool[M];

  for (ll i = 0; i < M; i++) {
    cin >> a[i] >> b[i] >> c[i];
    result[i] = false;
    a[i]--;
    b[i]--;
    connection[a[i]].push_back(make_pair(make_pair(i, b[i]), c[i]));
    connection[b[i]].push_back(make_pair(make_pair(i, a[i]), c[i]));
  }

  for (ll i = 0; i < N; i++) {

    // ダイクストラ
    priority_queue<pair<ll, ll>> pq;
    // weight[v]に始点sからvまでの最短コストを保存する
    ll weight[N];
    // 訪問状態を記録
    bool searched[N];
    //
    ll parent[N];
    for (ll i = 0; i < N; i++) {
      searched[i] = false;
      weight[i] = LLONG_MAX;
    }

    pq.push(make_pair(0, i));

    // priority_queue dicstra
    while (!pq.empty()) {
      pair<ll, ll> first = pq.top();
      pq.pop();
      ll node = first.second;
      ll u = -first.first;
      // cout << node << "/" << u << endl;
      searched[node] = true;

      for (pair<pair<ll, ll>, ll> target : connection[node]) {
        ll targetNode = target.first.second;
        ll targetCost = target.second;
        if (searched[targetNode])
          continue;
        if (targetCost + u < weight[targetNode]) {
          // cout << i << "/" << node << ":" << targetCost << "," << u << endl;
          parent[targetNode] = target.first.first;
          weight[targetNode] = targetCost + u;
          pair<ll, ll> newPair = make_pair(weight[targetNode] * -1, targetNode);
          pq.push(newPair);
        }
      }
    }

    for (ll n = 0; n < N; n++) {
      if (n == i)
        continue;
      result[parent[n]] = true;
    }
  }

  ll answer = 0;
  for (ll i = 0; i < M; i++) {
    if (result[i] == false) {
      answer++;
    }
  }
  cout << answer;

  return 0;
}

Fixed submission:
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>
// https://qiita.com/ofutonfuton/items/92b1a6f4a7775f00b6ae

using namespace std;
typedef long long ll;
std::unordered_map<ll, std::vector<pair<pair<ll, ll>, ll>>> connection;
ll N, M;
int result = 0;

int main() {
  cin >> N >> M;
  ll *a = new ll[M];
  ll *b = new ll[M];
  ll *c = new ll[M];
  bool *result = new bool[M];

  for (ll i = 0; i < M; i++) {
    cin >> a[i] >> b[i] >> c[i];
    result[i] = false;
    a[i]--;
    b[i]--;
    connection[a[i]].push_back(make_pair(make_pair(i, b[i]), c[i]));
    connection[b[i]].push_back(make_pair(make_pair(i, a[i]), c[i]));
  }

  for (ll i = 0; i < N; i++) {

    // ダイクストラ
    priority_queue<pair<ll, ll>> pq;
    // weight[v]に始点sからvまでの最短コストを保存する
    ll weight[N];
    // 訪問状態を記録
    bool searched[N];
    //
    ll parent[N];
    for (ll i = 0; i < N; i++) {
      searched[i] = false;
      weight[i] = LLONG_MAX;
    }

    pq.push(make_pair(0, i));

    // priority_queue dicstra
    while (!pq.empty()) {
      pair<ll, ll> first = pq.top();
      pq.pop();
      ll node = first.second;
      ll u = -first.first;
      // cout << node << "/" << u << endl;
      searched[node] = true;

      for (pair<pair<ll, ll>, ll> target : connection[node]) {
        ll targetNode = target.first.second;
        ll targetCost = target.second;
        if (searched[targetNode])
          continue;
        if (targetCost + u < weight[targetNode]) {
          // cout << i << "/" << node << ":" << targetCost << "," << u << endl;
          parent[targetNode] = target.first.first;
          weight[targetNode] = targetCost + u;
          pair<ll, ll> newPair = make_pair(weight[targetNode] * -1, targetNode);
          pq.push(newPair);
        }
      }
    }

    for (ll n = 0; n < N; n++) {
      if (n == i)
        continue;
      result[parent[n]] = true;
    }
  }

  ll answer = 0;
  for (ll i = 0; i < M; i++) {
    if (result[i] == false) {
      answer++;
    }
  }
  cout << answer;

  return 0;
}