#include <bits/stdc++.h>
using namespace std;
struct edge {
  int v, d;
  int z;
};
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<vector<int> > c(n, vector<int>(0));
  vector<edge> e(m);
  for (int i = 0; i < m; ++i) {
    int t;
    cin >> e[i].v >> e[i].d >> e[i].z;
    --e[i].v, --e[i].d;
    c[e[i].v].push_back(i);
    c[e[i].d].push_back(i);
  }
  vector<pair<int, int> > d(n, pair<int, int>(1000000000, 1000000000));
  d[0] = pair<int, int>(0, 0);
  vector<int> p(n);
  p[0] = -1;
  deque<int> q;
  q.push_back(0);
  while (!q.empty()) {
    int v = q.front();
    q.pop_front();
    for (int i = 0; i < c[v].size(); ++i) {
      int next = e[c[v][i]].d == v ? e[c[v][i]].v : e[c[v][i]].d;
      if (make_pair(d[v].first + 1, d[v].second - e[c[v][i]].z) < d[next]) {
        d[next] = make_pair(d[v].first + 1, d[v].second - e[c[v][i]].z);
        q.push_back(next);
        p[next] = c[v][i];
      }
    }
  }
  int cnt = 0;
  int ed = p[n - 1], pv = n - 1;
  while (ed != -1) {
    if (e[ed].v == pv)
      pv = e[ed].d;
    else
      pv = e[ed].v;
    if (e[ed].z == 0) {
      e[ed].z = -1;
      ++cnt;
    } else
      e[ed].z = -3;
    ed = p[pv];
  }
  for (int i = 0; i < m; ++i) {
    if (e[i].z > 0) {
      ++cnt;
      e[i].z = -2;
    }
  }
  cout << cnt << endl;
  for (int i = 0; i < m; ++i) {
    if (e[i].z == -1)
      cout << e[i].v + 1 << " " << e[i].d + 1 << " " << 1 << endl;
    else if (e[i].z == -2)
      cout << e[i].v + 1 << " " << e[i].d + 1 << " " << 0 << endl;
  }
  return 0;
}
