#include <bits/stdc++.h>
using namespace std;
int ara[100007], tra[100007], nra[100007], siz[100007], vis[100007],
    dist[100007], ord[100007], dro[100007];
int dp[100007], ck[100007], tk[100007], xra[100007];
vector<int> adj[100007], bdj[100007], tdj[100007];
int main() {
  int n, m, a, b, c, i, j, k, x;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d %d %d", &a, &b, &x);
    ara[i] = a;
    tra[i] = b;
    nra[i] = x;
    adj[a].push_back(b);
    bdj[a].push_back(x);
    tdj[a].push_back(i);
    siz[a]++;
    adj[b].push_back(a);
    bdj[b].push_back(x);
    tdj[b].push_back(i);
    siz[b]++;
  }
  vector<pair<int, int> > vct;
  int fr, sc, tr;
  queue<int> qu;
  qu.push(1);
  vis[1] = 1;
  dist[1] = 0;
  vct.push_back(make_pair(dist[1], 1));
  int u, v, lst, sz;
  while (!qu.empty()) {
    v = qu.front();
    qu.pop();
    sz = siz[v];
    for (i = 0; i < sz; i++) {
      u = adj[v][i];
      if (vis[u] == 0) {
        dist[u] = dist[v] + 1;
        vis[u] = 1;
        qu.push(u);
        vct.push_back(make_pair(dist[u], u));
      }
    }
  }
  sort(vct.begin(), vct.end());
  for (i = 0; i < n; i++) {
    fr = vct[i].first;
    sc = vct[i].second;
    ord[sc] = i + 1;
    dro[i + 1] = sc;
    if (sc == n) {
      lst = i + 1;
      break;
    }
  }
  int idx, e, f, g, h, nd;
  for (idx = lst; idx >= 1; idx--) {
    if (idx == lst) {
      dp[idx] = 0;
    } else {
      dp[idx] = -777777;
      nd = dro[idx];
      sz = siz[nd];
      ck[idx] = -1;
      tk[idx] = -1;
      for (i = 0; i < sz; i++) {
        fr = adj[nd][i];
        sc = bdj[nd][i];
        tr = tdj[nd][i];
        if (dist[fr] == dist[nd] + 1) {
          e = ord[fr];
          if (e > idx && e <= lst) {
            h = sc + dp[e];
            if (h > dp[idx]) {
              dp[idx] = h;
              ck[idx] = e;
              tk[idx] = tr;
            }
          }
        }
      }
    }
  }
  int p, q, r, s, w;
  p = 1;
  while (1) {
    if (p == lst) break;
    q = ck[p];
    w = tk[p];
    xra[w] = 1;
    p = q;
    if (p == lst) break;
  }
  k = 0;
  for (i = 1; i <= m; i++) {
    a = ara[i];
    b = tra[i];
    x = nra[i];
    if (x == 1) {
      if (xra[i] == 0) k++;
    } else {
      if (xra[i] == 1) k++;
    }
  }
  printf("%d\n", k);
  for (i = 1; i <= m; i++) {
    a = ara[i];
    b = tra[i];
    x = nra[i];
    if (x == 1) {
      if (xra[i] == 0) {
        printf("%d %d 0\n", a, b);
      }
    } else {
      if (xra[i] == 1) {
        printf("%d %d 1\n", a, b);
      }
    }
  }
  return 0;
}
