#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 5;
bool res[maxN];
vector<int> p[maxN];
int w[maxN], tr[maxN], l[maxN];
struct edge {
  int u, v;
  bool z;
} e[maxN];
struct path {
  int in, v, l, w;
};
queue<path> q;
int _v(int u, int in) { return e[in].u != u ? e[in].u : e[in].v; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int ans = 0;
  for (int i = 1; i <= m; ++i) {
    cin >> e[i].u >> e[i].v >> e[i].z;
    p[e[i].u].push_back(i);
    p[e[i].v].push_back(i);
    ans += e[i].z;
  }
  path cur;
  cur.in = cur.l = cur.w = 0;
  cur.v = 1;
  q.push(cur);
  int lim = n;
  memset(w, -1, sizeof(w));
  memset(l, -1, sizeof(l));
  while (!q.empty() && q.front().l <= lim) {
    cur = q.front();
    q.pop();
    if (l[cur.v] == -1) l[cur.v] = cur.l;
    if (l[cur.v] == cur.l)
      if (w[cur.v] < cur.w) {
        tr[cur.v] = cur.in;
        w[cur.v] = cur.w;
      }
    if (cur.v == n) lim = cur.l;
    for (int i : p[cur.v]) {
      int v = _v(cur.v, i);
      if (w[v] != -1) continue;
      path nx;
      nx.in = i;
      nx.v = v;
      nx.l = cur.l + 1;
      nx.w = cur.w + e[i].z;
      q.push(nx);
    }
  }
  cout << ans + lim - (w[n] << 1) << '\n';
  int v = n;
  while (v != 1) {
    res[tr[v]] = true;
    if (!e[tr[v]].z) cout << e[tr[v]].u << ' ' << e[tr[v]].v << " 1\n";
    v = _v(v, tr[v]);
  }
  for (int i = 1; i <= m; ++i)
    if (!res[i] && e[i].z) cout << e[i].u << ' ' << e[i].v << " 0\n";
  return 0;
}
