#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ta, tb;
  std::cin >> n >> m;
  int a[m], b[m], c[m];
  int d[n + 1][n + 1];
  fill(d[0], d[n + 1], 1 << 25);
  int ans = 0, temp = 1;
  for (int i = 0; i < m; i++) {
    std::cin >> ta >> tb >> c[i];
    a[i] = ta - 1, b[i] = tb - 1;
    d[a[i]][b[i]] = c[i];
    d[b[i]][a[i]] = c[i];
  }
  for (int i = 0; i < n; i++) {
    d[i][i] = 0;
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[j][k]);
        d[j][i] = d[i][j];
      }
    }
  }
  for (int i = 0; i < n; i++)
    cout << d[i][0] << " " << d[i][1] << " " << d[i][2] << endl;
  for (int k = 0; k < m; k++) {
    temp = 1;
    for (int i = 0; i < n; i++) {
      if (d[i][a[k]] + c[k] == d[i][b[k]]) {
        temp *= 0;
        break;
      }
    }
    ans += temp;
  }
  cout << ans << endl;
}
