#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int INF = (1 << 29);
const int MAX = 100009;
struct abc {
  int to;
  bool fl;
  abc() { ; }
  abc(int _to, bool _fl) {
    to = _to;
    fl = _fl;
  }
};
int n, m;
int d1[MAX], dn[MAX], op[MAX], working;
int fo[MAX], to[MAX], open[MAX], par[MAX], path[MAX];
vector<abc> G[MAX];
bool visi[MAX];
void BFS(int st, int d[]) {
  queue<int> Q;
  Q.push(st);
  memset(d, -1, sizeof(d));
  for (int i = 1; i <= n; i++) d[i] = -1;
  d[st] = 0;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int i = 0; i < (int)G[u].size(); i++) {
      int v = G[u][i].to;
      if (d[v] != -1) continue;
      Q.push(v);
      d[v] = d[u] + 1;
    }
  }
  return;
}
void solve() {
  queue<int> Q;
  memset(op, -1, sizeof(op));
  memset(visi, 0, sizeof(visi));
  op[1] = 0;
  Q.push(1);
  int d = d1[n];
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    if (visi[u]) continue;
    visi[u] = true;
    for (int i = 0; i < (int)G[u].size(); i++) {
      int v = G[u][i].to;
      int flN = G[u][i].fl;
      if (d1[v] + dn[v] != d || d1[u] + 1 + dn[v] != d || visi[v]) continue;
      if (op[v] != -1 && op[v] >= op[u] + flN) continue;
      Q.push(v);
      op[v] = op[u] + flN;
      par[v] = u;
    }
  }
  int node = n;
  while (node != 1) {
    path[node] = par[node];
    node = path[node];
  }
  cout << working + d - 2 * op[n] << endl;
  for (int i = 0; i < m; i++) {
    if (path[fo[i]] == to[i] || path[to[i]] == fo[i]) {
      if (!open[i]) cout << fo[i] << " " << to[i] << " " << 1 << endl;
    } else if (open[i])
      cout << fo[i] << " " << to[i] << " " << 0 << endl;
  }
  return;
}
int main() {
  while (cin >> n >> m) {
    for (int i = 0; i <= n; i++) G[i].clear();
    working = 0;
    for (int i = 0; i < m; i++) {
      scanf("%d %d %d", fo + i, to + i, open + i);
      G[fo[i]].push_back(abc(to[i], open[i]));
      G[to[i]].push_back(abc(fo[i], open[i]));
      working += open[i];
    }
    BFS(1, d1);
    BFS(n, dn);
    solve();
  }
  return 0;
}
