#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 50, INF = 1e9;
int dist[MAX_N], f[MAX_N], par[MAX_N];
map<pair<int, int>, bool> mp;
int n, m, x, y, z;
vector<pair<int, int>> adj[MAX_N];
queue<int> q;
pair<pair<int, int>, int> edge[MAX_N];
int f1;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> x >> y >> z;
    dist[x] = INF;
    dist[y] = INF;
    if (z) f1++;
    adj[x].push_back({y, z});
    adj[y].push_back({x, z});
    if (x > y) swap(x, y);
    edge[i] = {{x, y}, z};
  }
  q.push(1);
  dist[1] = 0;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (auto u : adj[v]) {
      if (dist[v] + 1 < dist[u.first]) {
        dist[u.first] = dist[v] + 1;
        par[u.first] = v;
        f[u.first] = f[v] + (u.second == 1);
        q.push(u.first);
      } else if (dist[v] + 1 == dist[u.first]) {
        if (f[u.first] < f[v] + (u.second == 1)) {
          par[u.first] = v;
          f[u.first] = f[v] + (u.second == 1);
        }
      }
    }
  }
  int v = n;
  while (v != 1) {
    x = par[v];
    y = v;
    if (x > y) swap(x, y);
    mp[{x, y}] = true;
    v = par[v];
  }
  cout << f1 + 2 * (dist[n] - f[n]) - dist[n] << "\n";
  for (int i = 1; i <= m; ++i) {
    if (mp[{edge[i].first.first, edge[i].first.second}] == 1 &&
        edge[i].second == 0) {
      cout << edge[i].first.first << " " << edge[i].first.second << " "
           << (edge[i].second ^ 1) << "\n";
    } else if (mp[{edge[i].first.first, edge[i].first.second}] == 0 &&
               edge[i].second == 1) {
      cout << edge[i].first.first << " " << edge[i].first.second << " "
           << (edge[i].second ^ 1) << "\n";
    }
  }
}
