#include <bits/stdc++.h>
inline int read() {
  register int x;
  register char c;
  while (!isdigit(c = getchar()))
    ;
  x = c ^ 48;
  while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c ^ 48);
  return x;
}
int n, m, ans;
int edge_size, head[100010];
struct Edge {
  int node;
  int val;
  int next;
} edge[100010 << 1];
inline void add_edge(int u, int v, int val) {
  edge[++edge_size] = (Edge){v, val, head[u]};
  head[u] = edge_size;
}
int pree[100010], pren[100010];
bool in[100010], use[100010], print[100010];
int l, r, que[100010 << 4];
struct Dis {
  int d1, d2;
} dis[100010];
inline void spfa() {
  for (int i = 1; i <= n; i++) {
    dis[i] = (Dis){0x7fffffff, 0x7fffffff};
  }
  dis[1] = (Dis){0, 0};
  que[++r] = 1;
  in[1] = true;
  while (l < r) {
    int u = que[++l];
    in[u] = false;
    for (int e = head[u], v; v = edge[e].node, e; e = edge[e].next) {
      if (dis[v].d1 > dis[u].d1 + 1) {
        dis[v] = (Dis){dis[u].d1 + 1, dis[u].d2 + !edge[e].val};
        pren[v] = u;
        pree[v] = e + 1 >> 1;
        if (!in[v]) {
          in[v] = true;
          que[++r] = v;
        }
      } else if (dis[v].d1 == dis[u].d1 + 1) {
        if (dis[v].d2 > dis[u].d2 + !edge[e].val) {
          dis[v].d2 = dis[u].d2 + !edge[e].val;
          pren[v] = u;
          pree[v] = e + 1 >> 1;
          if (!in[v]) {
            in[v] = true;
            que[++r] = v;
          }
        }
      }
    }
  }
}
int main() {
  n = read();
  m = read();
  for (int i = 1, u, v, w; i <= m; i++) {
    u = read();
    v = read();
    w = read();
    add_edge(u, v, w);
    add_edge(v, u, w);
  }
  spfa();
  int t = n;
  while (pren[t]) {
    use[pree[t]] = true;
    t = pren[t];
  }
  for (int e = 1; e <= m; e++) {
    if (use[e] && !edge[e << 1].val) {
      ans++;
      print[e] = true;
    }
    if (!use[e] && edge[e << 1].val) {
      ans++;
      print[e] = true;
    }
  }
  printf("%d\n", ans);
  for (int e = 1; e <= m; e++) {
    if (print[e]) {
      printf("%d %d %d\n", edge[e << 1].node, edge[(e << 1) - 1].node,
             !edge[e << 1].val);
    }
  }
  return 0;
}
