Language: C++

#include <iostream>                                                             #include <algorithm>                                                            #include <vector>                                                               #include <map>
using namespace std;
void count(
  map<pair<int, int>, bool>& edges,
  const vector<vector<int>>& middle,
  int src, int dst
) {
  int m = middle[src][dst];
  int min = src < dst ? src : dst;
  int max = src < dst ? dst : src;
  if (m < 0) {
    edges[make_pair(min, max)] = true;
  } else {
    count(edges, middle, src, m);
    count(edges, middle, m, dst);
  }
}

int main()
{
  int N, M;
  cin >> N >> M;
  if (N - M == 1) {
    cout << 0 << endl;
    return 0;
  }

  vector<vector<int>> distance(N, vector<int>(N, -1));
  for (int i = 0; i < M; ++i) {
    int src, dst, length;
    cin >> src >> dst >> length;
    --src; --dst;
    distance[src][dst] = distance[dst][src] = length;
  }

  vector<vector<int>> middle(N, vector<int>(N, -1));
  for (int k = 0; k < N; ++k) {
    for (int s = 0; s < N; ++s) {
      for (int t = 0; t < N; ++t) {
        if (distance[s][k] < 0 or distance[k][t] < 0) continue;
        int sum = distance[s][k] + distance[k][t];
        if (distance[s][t] < 0 or sum < distance[s][t]) {
          distance[s][t] = distance[t][s] = sum;
          middle[s][t] = middle[t][s] = k;
        }
      }
    }
  }

  map<pair<int, int>, bool> edges;
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      count(edges, middle, i, j);
    }
  }

  cout << (M - edges.size()) << endl;
  return 0;
}

Compiler output:
a.cc:1:81: warning: extra tokens at end of #include directive
    1 | #include <iostream>                                                             #include <algorithm>                                                            #include <vector>                                                               #include <map>
      |                                                                                 ^
a.cc:3:6: error: variable or field 'count' declared void
    3 | void count(
      |      ^~~~~
a.cc:4:3: error: 'map' was not declared in this scope
    4 |   map<pair<int, int>, bool>& edges,
      |   ^~~
a.cc:2:1: note: 'std::map' is defined in header '<map>'; this is probably fixable by adding '#include <map>'
    1 | #include <iostream>                                                             #include <algorithm>                                                            #include <vector>                                                               #include <map>
  +++ |+#include <map>
    2 | using namespace std;
a.cc:4:21: error: expected primary-expression before ',' token
    4 |   map<pair<int, int>, bool>& edges,
      |                     ^
a.cc:4:23: error: expected primary-expression before 'bool'
    4 |   map<pair<int, int>, bool>& edges,
      |                       ^~~~
a.cc:5:3: error: expected primary-expression before 'const'
    5 |   const vector<vector<int>>& middle,
      |   ^~~~~
a.cc:6:3: error: expected primary-expression before 'int'
    6 |   int src, int dst
      |   ^~~
a.cc:6:12: error: expected primary-expression before 'int'
    6 |   int src, int dst
      |            ^~~
a.cc: In function 'int main()':
a.cc:28:3: error: 'vector' was not declared in this scope
   28 |   vector<vector<int>> distance(N, vector<int>(N, -1));
      |   ^~~~~~
a.cc:2:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    1 | #include <iostream>                                                             #include <algorithm>                                                            #include <vector>                                                               #include <map>
  +++ |+#include <vector>
    2 | using namespace std;
a.cc:28:17: error: expected primary-expression before 'int'
   28 |   vector<vector<int>> distance(N, vector<int>(N, -1));
      |                 ^~~
a.cc:33:13: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   33 |     distance[src][dst] = distance[dst][src] = length;
      |             ^
a.cc:33:34: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   33 |     distance[src][dst] = distance[dst][src] = length;
      |                                  ^
a.cc:36:17: error: expected primary-expression before 'int'
   36 |   vector<vector<int>> middle(N, vector<int>(N, -1));
      |                 ^~~
a.cc:40:21: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   40 |         if (distance[s][k] < 0 or distance[k][t] < 0) continue;
      |                     ^
a.cc:40:43: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   40 |         if (distance[s][k] < 0 or distance[k][t] < 0) continue;
      |                                           ^
a.cc:41:27: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   41 |         int sum = distance[s][k] + distance[k][t];
      |                           ^
a.cc:41:44: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   41 |         int sum = distance[s][k] + distance[k][t];
      |                                            ^
a.cc:42:21: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   42 |         if (distance[s][t] < 0 or sum < distance[s][t]) {
      |                     ^
a.cc:42:49: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   42 |         if (distance[s][t] < 0 or sum < distance[s][t]) {
      |                                                 ^
a.cc:43:19: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   43 |           distance[s][t] = distance[t][s] = sum;
      |                   ^
a.cc:43:36: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   43 |           distance[s][t] = distance[t][s] = sum;
      |                                    ^
a.cc:44:11: error: 'middle' was not declared in this scope
   44 |           middle[s][t] = middle[t][s] = k;
      |           ^~~~~~
a.cc:50:3: error: 'map' was not declared in this scope
   50 |   map<pair<int, int>, bool> edges;
      |   ^~~
a.cc:50:3: note: 'std::map' is defined in header '<map>'; this is probably fixable by adding '#include <map>'
a.cc:50:21: error: expected primary-expression before ',' token
   50 |   map<pair<int, int>, bool> edges;
      |                     ^
a.cc:50:23: error: expected primary-expression before 'bool'
   50 |   map<pair<int, int>, bool> edges;
      |                       ^~~~
a.cc:53:13: error: 'edges' was not declared in this scope
   53 |       count(edges, middle, i, j);
      |             ^~~~~
a.cc:53:20: error: 'middle' was not declared in this scope
   53 |       count(edges, middle, i, j);
      |                    ^~~~~~
a.cc:53:7: error: 'count' was not declared in this scope
   53 |       count(edges, middle, i, j);
      |       ^~~~~
a.cc:57:16: error: 'edges' was not declared in this scope
   57 |   cout << (M - edges.size()) << endl;
      |                ^~~~~