#include <bits/stdc++.h>
using namespace std;
int len[100005], rep[100005], prv[100005];
void run() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  run();
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, bool> > > g(100005);
  map<pair<int, int>, bool> tell;
  for (int i = 0; i < m; i++) {
    int f, t, s;
    cin >> f >> t >> s;
    g[f].push_back({t, s});
    g[t].push_back({f, s});
    if (f > t) {
      int sw = f;
      f = t;
      t = sw;
    }
    tell[{f, t}] = s;
  }
  queue<int> q;
  for (int i = 0; i <= n; i++) len[i] = INT_MAX, rep[i] = INT_MAX;
  q.push(1);
  len[1] = 0;
  rep[1] = 0;
  prv[1] = -1;
  int node;
  while (!q.empty()) {
    node = q.front();
    q.pop();
    if (node == n) break;
    for (int i = 0; i < g[node].size(); i++) {
      int child = g[node][i].first;
      bool ss = g[node][i].second;
      if (len[node] + 1 < len[child]) {
        len[child] = len[node] + 1;
        rep[child] = rep[node] + 1 - ss;
        prv[child] = node;
        q.push(child);
      } else if (len[node] + 1 <= len[child])
        if (rep[child] > rep[node] + 1 - ss) {
          rep[child] = rep[node] + 1 - ss;
          prv[child] = node;
        }
    }
  }
  int aff = 0;
  vector<pair<int, int> > v, v2;
  while (prv[n] != -1) {
    int f = prv[n], t = n;
    if (f > t) {
      int sw = f;
      f = t;
      t = sw;
    }
    if (tell[{f, t}] == 0) {
      aff++;
      v.push_back({f, t});
    } else
      tell[{f, t}] = 0;
    n = prv[n];
  }
  for (map<pair<int, int>, bool>::iterator itr = tell.begin();
       itr != tell.end(); itr++)
    if (itr->second) {
      aff++;
      v2.push_back({itr->first.first, itr->first.second});
    }
  cout << aff << endl;
  for (int i = 0; i < v.size(); i++)
    cout << v[i].first << " " << v[i].second << " " << 1 << endl;
  for (int i = 0; i < v2.size(); i++)
    cout << v2[i].first << " " << v2[i].second << " " << 0 << endl;
  return 0;
}
