#include <bits/stdc++.h>
const int MAXN = 1e5 + 7;
using namespace std;
int num, head[MAXN], Head[MAXN], dep[MAXN], b[MAXN], n, m, s, t, numm,
    dis[MAXN], to[MAXN], change[MAXN], flag;
struct E {
  int u, v, w;
} e[MAXN << 1];
struct po {
  int nxt, to, dis, num;
} edge[MAXN << 1], Edge[MAXN << 1];
inline void add_edge(int from, int to, int dis) {
  edge[++num].nxt = head[from];
  edge[num].to = to;
  edge[num].dis = dis;
  head[from] = num;
}
inline void Add_edge(int from, int to, int dis) {
  Edge[++numm].nxt = Head[from];
  Edge[numm].to = to;
  Edge[numm].dis = dis;
  Head[from] = numm;
}
inline void bfs1() {
  memset(dep, 0, sizeof(dep));
  queue<int> q;
  q.push(s);
  dep[s] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = Head[u]; i; i = Edge[i].nxt) {
      int v = Edge[i].to;
      if (dep[v]) continue;
      dep[v] = dep[u] + 1;
      if (v == t) return;
      q.push(v);
    }
  }
}
inline void bfs2() {
  queue<int> q;
  q.push(t);
  b[t] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = Head[u]; i; i = Edge[i].nxt) {
      int v = Edge[i].to;
      if (dep[v] == dep[u] - 1) {
        change[i] = 0;
        add_edge(v, u, Edge[i].dis);
        edge[num].num = (i + 1) / 2;
        if (!b[v]) {
          b[v] = 1;
          q.push(v);
        }
      }
    }
  }
}
inline void spfa() {
  memset(b, 0, sizeof(b));
  memset(dis, -1, sizeof(dis));
  queue<int> q;
  q.push(s);
  dis[s] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    b[u] = 0;
    for (int i = head[u]; i; i = edge[i].nxt) {
      int v = edge[i].to;
      if (dis[v] < dis[u] + edge[i].dis) {
        dis[v] = dis[u] + edge[i].dis;
        if (!b[v]) {
          b[v] = 1;
          q.push(v);
        }
      }
    }
  }
}
inline void dfs(int u, int l) {
  if (flag == 1) return;
  if (l == dis[t] && u == t) {
    flag = 1;
    return;
  }
  for (int i = head[u]; i; i = edge[i].nxt) {
    int v = edge[i].to;
    if (l + edge[i].dis <= to[v]) continue;
    to[v] = l + edge[i].dis;
    change[edge[i].num] = 1;
    dfs(v, to[v]);
    if (flag == 1) return;
    change[edge[i].num] = 0;
  }
}
int main() {
  cin >> n >> m;
  s = 1;
  t = n;
  for (int i = 1; i <= m; i++) {
    change[i] = 2;
    cin >> e[i].u >> e[i].v >> e[i].w;
    int u, v, w;
    u = e[i].u;
    v = e[i].v;
    w = e[i].w;
    Add_edge(u, v, w);
    Add_edge(v, u, w);
  }
  bfs1();
  bfs2();
  spfa();
  memset(to, -1, sizeof(to));
  dfs(s, 0);
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    if (change[i] != 1 && e[i].w == 1) {
      ans++;
    }
    if (change[i] == 1 && e[i].w == 0) {
      ans++;
    }
  }
  printf("%d\n", ans);
  for (int i = 1; i <= m; i++) {
    if (change[i] != 1 && e[i].w == 1) {
      printf("%d %d 0\n", e[i].u, e[i].v);
    }
    if (change[i] == 1 && e[i].w == 0) {
      printf("%d %d 1\n", e[i].u, e[i].v);
    }
  }
  return 0;
}
