#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > graph[100005];
int d[100005], x[100005], y[100005], z[100005], good[100005], bedge[100005],
    par[100005];
int n, m;
map<pair<int, int>, int> Ma;
queue<int> q;
void print_nodes(int a) {
  if (a == 1)
    return;
  else if (z[Ma[make_pair(a, par[a])]]) {
    z[Ma[make_pair(a, par[a])]] = 0;
    print_nodes(par[a]);
  } else {
    cout << par[a] << " " << a << " " << 1 << endl;
    print_nodes(par[a]);
  }
}
int main() {
  int i, j, k, wedge;
  wedge = 0;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> x[i] >> y[i] >> z[i];
    Ma[make_pair(x[i], y[i])] = i;
    Ma[make_pair(y[i], x[i])] = i;
    graph[x[i]].push_back(make_pair(y[i], z[i]));
    graph[y[i]].push_back(make_pair(x[i], z[i]));
    if (z[i] == 1) wedge++;
  }
  for (i = 0; i <= n; i++) d[i] = 1e9;
  q.push(1);
  d[1] = 0;
  good[1] = 0;
  par[1] = 1;
  while (!q.empty()) {
    long long el = q.front();
    q.pop();
    for (auto e : graph[el]) {
      int u = e.first;
      if (d[u] > d[el] + 1) {
        q.push(u);
        d[u] = d[el] + 1;
        k = 1 - e.second;
        bedge[u] = bedge[el] + k;
        par[u] = el;
      } else if (d[u] == (d[el] + 1)) {
        k = 1 - e.second;
        if (bedge[u] > bedge[el] + k) {
          bedge[u] = bedge[el] + k;
          par[u] = el;
        }
      }
    }
  }
  cout << bedge[n] + wedge - (d[n] - bedge[n]) << endl;
  print_nodes(n);
  for (i = 0; i < m; i++) {
    if (z[i]) cout << x[i] << " " << y[i] << " " << 0 << endl;
  }
  return 0;
}
