#include <bits/stdc++.h>
using namespace std;
int d1[100010], dn[100010], Max[100010], vis[100010], par[100010], path[100010],
    x[100010], y[100010], z[100010];
vector<pair<int, int> > g[100010];
int main() {
  int i, t, n, m, u, v, zz, top, d, tot = 0;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> x[i] >> y[i] >> z[i];
    g[x[i]].push_back(make_pair(y[i], z[i]));
    g[y[i]].push_back(make_pair(x[i], z[i]));
    tot += z[i];
  }
  memset(vis, 0, sizeof(vis));
  memset(d1, -1, sizeof(d1));
  queue<int> q;
  d1[1] = 0;
  q.push(1);
  while (!q.empty()) {
    top = q.front();
    q.pop();
    for (i = 0; i < g[top].size(); i++) {
      v = g[top][i].first;
      if (d1[v] != -1) continue;
      d1[v] = d1[top] + 1;
      q.push(v);
    }
  }
  memset(dn, -1, sizeof(dn));
  dn[n] = 0;
  q.push(n);
  while (!q.empty()) {
    top = q.front();
    q.pop();
    for (i = 0; i < g[top].size(); i++) {
      v = g[top][i].first;
      if (dn[v] != -1) continue;
      dn[v] = dn[top] + 1;
      q.push(v);
    }
  }
  d = d1[n];
  q.push(1);
  memset(Max, -1, sizeof(Max));
  Max[1] = 0;
  while (!q.empty()) {
    top = q.front();
    q.pop();
    if (vis[top]) continue;
    vis[top] = 1;
    for (i = 0; i < g[top].size(); i++) {
      v = g[top][i].first;
      zz = g[top][i].second;
      if (d1[v] + dn[v] != d || d1[top] + 1 + dn[v] != d || vis[v]) continue;
      if (Max[v] != -1 && Max[v] >= Max[top] + zz) continue;
      Max[v] = Max[top] + zz;
      q.push(v);
      par[v] = top;
    }
  }
  for (v = n; v != 1; v = par[v]) path[v] = par[v];
  cout << tot + d - 2 * Max[n] << endl;
  for (i = 0; i < m; i++) {
    if (path[x[i]] == y[i] || path[y[i]] == x[i]) {
      if (!z[i]) cout << x[i] << " " << y[i] << " 1\n";
    } else if (z[i])
      cout << x[i] << " " << y[i] << " 0\n";
  }
  return 0;
}
