#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int read() {
  char ch = ' ';
  int f = 1;
  int x = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
const int N = 1e5 + 100;
const int M = 2e5 + 100;
struct node {
  int v, nxt;
  int w;
  int in;
} edge[200005];
int head[100005], cnt;
void add(int u, int v, int w) {
  cnt;
  edge[cnt].v = v;
  edge[cnt].w = w;
  edge[cnt].in = 0;
  edge[cnt].nxt = head[u];
  head[u] = cnt++;
}
int dis[100005], f[100005], pre[100005], e[100005];
bool vis[100005];
int n;
void spfa() {
  queue<int> q;
  memset(dis, inf, sizeof(dis));
  memset(f, inf, sizeof(f));
  memset(vis, 0, sizeof(vis));
  dis[1] = 0;
  f[1] = 0;
  vis[1] = true;
  pre[1] = 1;
  q.push(1);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = false;
    if (u == n) return;
    for (int i = head[u]; i != -1; i = edge[i].nxt) {
      int v = edge[i].v;
      int w = edge[i].w ^ 1;
      if (dis[u] + 1 < dis[v] || (dis[u] + 1 == dis[v] && f[u] + w < f[v])) {
        dis[v] = dis[u] + 1;
        f[v] = f[u] + w;
        pre[v] = u;
        e[v] = i;
        if (!vis[v]) {
          q.push(v);
          vis[v] = true;
        }
      }
    }
  }
}
void bfs() {
  queue<int> q;
  memset(vis, 0, sizeof(vis));
  vis[1] = true;
  q.push(1);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = false;
    for (int i = head[u]; i != -1; i = edge[i].nxt) {
      if (edge[i].in == -1) continue;
      int v = edge[i].v;
      if (edge[i].in && !edge[i].w) {
        cout << u << " " << v << " " << 1 << endl;
      } else if (!edge[i].in && edge[i].w) {
        cout << u << " " << v << " " << 0 << endl;
      }
      edge[i].in = edge[i ^ 1].in = -1;
      if (!vis[v]) {
        q.push(v);
        vis[v] = true;
      }
    }
  }
}
int main() {
  memset(head, -1, sizeof(head));
  int m;
  n = read();
  m = read();
  int i, j;
  int sum = 0;
  for (i = 1; i <= m; i++) {
    int u = read(), v = read(), w = read();
    add(u, v, w);
    add(v, u, w);
    if (w == 1) sum++;
  }
  spfa();
  for (int u = n; u != pre[u]; u = pre[u]) {
    edge[e[u]].in = 1;
    edge[e[u] ^ 1].in = 1;
  }
  printf("%d\n", sum - dis[n] + 2 * f[n]);
  bfs();
  return 0;
}
