#include <bits/stdc++.h>
using namespace std;
int from[111111];
int to[111111];
int st[111111];
int type[111111];
int n, m;
vector<pair<int, int> > g[111111];
priority_queue<pair<int, int> > pr;
pair<int, int> res[111111];
pair<int, int> gone[222222];
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> from[i];
    cin >> to[i];
    cin >> st[i];
    from[i]--;
    to[i]--;
    g[from[i]].push_back(make_pair(to[i], i));
    g[to[i]].push_back(make_pair(from[i], i));
  }
  res[0].first = 0;
  for (int i = 1; i < n; i++) {
    res[i].first = 1000000;
  }
  pr.push(make_pair(0, 0));
  while (!pr.empty()) {
    int v = pr.top().second;
    int dist = -pr.top().first;
    pr.pop();
    for (int i = 0; i < g[v].size(); i++) {
      int t = g[v][i].first;
      int ind = g[v][i].second;
      int newDist = dist + 1;
      int newGood = res[v].second;
      if (st[ind] == 1) newGood++;
      if (newDist < res[t].first) {
        res[t].first = newDist;
        res[t].second = newGood;
        pr.push(make_pair(-newDist, t));
        gone[t] = make_pair(v, ind);
        continue;
      }
      if (newDist == res[t].first && newGood > res[t].second) {
        res[t].first = newDist;
        res[t].second = newGood;
        pr.push(make_pair(-newDist, t));
        gone[t] = make_pair(v, ind);
        continue;
      }
    }
  }
  int v = n - 1;
  while (v != 0) {
    int ind = gone[v].second;
    type[ind] = 1;
    v = gone[v].first;
  }
  int r = 0;
  for (int i = 0; i < m; i++) {
    if (type[i] != st[i]) r++;
  }
  cout << r << endl;
  for (int i = 0; i < m; i++) {
    if (type[i] != st[i]) {
      printf("%d %d %d\n", from[i] + 1, to[i] + 1, type[i]);
    }
  }
  return 0;
}
