#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m, sz = 0, x, y, z;
  cin >> n >> m;
  vector<vector<pair<int, int>>> adj(n + 1);
  vector<pair<int, int>> dist(n + 1, {n, 0});
  vector<bool> vis(n + 1), path(n + 1);
  vector<int> prev(n + 1);
  for (int i = 0; i < m; i++) {
    cin >> x >> y >> z;
    adj[x].push_back({y, z});
    adj[y].push_back({x, z});
    sz += z;
  }
  queue<int> bfs;
  bfs.push(1);
  dist[1].first = 0;
  vis[1] = 1;
  while (!bfs.empty()) {
    int u = bfs.front();
    for (pair<int, int> e : adj[u]) {
      if (!vis[e.first]) {
        bfs.push(e.first);
        vis[e.first] = 1;
      }
      pair<int, int> newdist = {dist[u].first + 1, dist[u].second - e.second};
      if (dist[e.first] > newdist) {
        dist[e.first] = newdist;
        prev[e.first] = u;
      }
    }
    bfs.pop();
  }
  x = n;
  path[n] = 1;
  while (x != 1) {
    x = prev[x];
    path[x] = 1;
  }
  cout << (sz + dist[n].first + 2 * dist[n].second) << "\n";
  for (int u = 1; u <= n; u++) {
    if (path[u]) {
      for (auto e : adj[u]) {
        if (e.first > u && path[e.first] && e.second == 0)
          cout << u << " " << e.first << " 1\n";
      }
    } else {
      for (auto e : adj[u]) {
        if ((e.first > u || path[e.first]) && e.second == 1)
          cout << u << " " << e.first << " 0\n";
      }
    }
  }
  return 0;
}
