#include <bits/stdc++.h>
using namespace std;
const int maxn = 123102, maxm = 203423;
struct ed {
  int v, s;
  ed *nx;
  ed() {}
  ed(int v, int s, ed *nx) : v(v), s(s), nx(nx) {}
} * g1[maxn], *g2[maxn];
struct e2 {
  int a, b, c;
  e2() {}
  e2(int a, int b, int c) : a(a), b(b), c(c) {}
} E[maxm], op[maxm], om[maxm];
int co, cm;
void addedge(int u, int v, int k, ed **G) {
  G[u] = new ed(v, k, G[u]);
  G[v] = new ed(u, k, G[v]);
}
void bfs(int be, int *w, ed **g) {
  memset(w, 0x3f, maxn * sizeof(int));
  w[be] = 0;
  queue<int> Q;
  Q.push(be);
  while (!Q.empty()) {
    int o = Q.front();
    Q.pop();
    for (ed *p = g[o]; p; p = p->nx)
      if (w[p->v] == 0x3f3f3f3f) {
        w[p->v] = w[o] + 1;
        Q.push(p->v);
      }
  }
}
typedef int arr[maxn];
void work(int n, ed **g) {
  static arr dm, cnt, dp, come, come2;
  static bool inq[maxn], use[maxm];
  memset(dm, 0, sizeof(dm));
  memset(cnt, 0, sizeof(cnt));
  memset(inq, 0, sizeof(inq));
  memset(use, 0, sizeof(use));
  memset(dp, 63, sizeof(dp));
  dm[1] = 1;
  queue<int> Q;
  Q.push(1);
  while (!Q.empty()) {
    int o = Q.front();
    Q.pop();
    for (ed *p = g[o]; p; p = p->nx)
      if (!dm[p->v]) dm[p->v] = dm[o] + 1, Q.push(p->v);
  }
  for (int i = 1; i <= n; ++i)
    for (ed *p = g[i]; p; p = p->nx)
      if (dm[p->v] == dm[i] + 1) cnt[dm[i]] += om[p->s].c;
  Q.push(1);
  dp[1] = 0;
  inq[1] = true;
  while (!Q.empty()) {
    int o = Q.front();
    Q.pop();
    inq[o] = false;
    for (ed *p = g[o]; p; p = p->nx) {
      if (dm[p->v] != dm[o] + 1) continue;
      int wi = cnt[dm[o]] - om[p->s].c * 2 + 1;
      if (dp[p->v] > wi + dp[o]) {
        come[p->v] = p->s;
        come2[p->v] = o;
        dp[p->v] = wi + dp[o];
        if (!inq[p->v]) inq[p->v] = true, Q.push(p->v);
      }
    }
  }
  for (int o = n; o ^ 1; o = come2[o]) use[come[o]] = true;
  for (int i = 0; i < cm; ++i)
    if (use[i] && !om[i].c)
      op[co++] = e2(om[i].a, om[i].b, 1);
    else if (!use[i] && om[i].c)
      op[co++] = e2(om[i].a, om[i].b, 0);
}
int main() {
  static int d1[maxn], d2[maxn];
  int n, m, a;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", &E[i].a, &E[i].b, &E[i].c);
    addedge(E[i].a, E[i].b, E[i].c, g1);
  }
  bfs(1, d1, g1);
  a = d1[n] - 1;
  bfs(n, d2, g1);
  for (int i = 0; i < m; ++i) {
    if (d1[E[i].a] + d2[E[i].b] == a || d1[E[i].b] + d2[E[i].a] == a)
      addedge(E[i].a, E[i].b, cm, g2), om[cm++] = E[i];
    else if (E[i].c)
      op[co++] = e2(E[i].a, E[i].b, 0);
  }
  work(n, g2);
  printf("%d\n", co);
  for (int i = 0; i < co; ++i) printf("%d %d %d\n", op[i].a, op[i].b, op[i].c);
  return 0;
}
