#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
const int INF = 1000000000;
int N, M, num;
struct Edge {
  int u, v, type, next, f, id;
} edge[maxn * 2];
int dis[maxn], head[maxn];
int pre[maxn], cnt[maxn];
int vis[maxn], id[maxn];
void init() {
  num = 0;
  memset(head, -1, sizeof(head));
  memset(cnt, 0, sizeof(cnt));
  memset(pre, -1, sizeof(pre));
}
void add_edge(int u, int v, int type, int id) {
  edge[num].v = v;
  edge[num].u = u;
  edge[num].next = head[u];
  edge[num].type = type;
  edge[num].f = 1;
  edge[num].id = id;
  head[u] = num++;
}
void SPFA(int s, int t) {
  for (int i = 0; i <= N; i++) {
    dis[i] = INF;
    vis[i] = 0;
  }
  queue<int> q;
  q.push(s);
  vis[s] = 1;
  dis[s] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = 0;
    for (int i = head[u]; i != -1; i = edge[i].next) {
      int v = edge[i].v, w = edge[i].f;
      if ((dis[v] > dis[u] + w) ||
          (dis[v] == dis[u] + 1 && cnt[v] < cnt[u] + (edge[i].type))) {
        dis[v] = dis[u] + w;
        pre[v] = u;
        id[v] = edge[i].id;
        cnt[v] = cnt[u];
        cnt[v] += edge[i].type;
        if (!vis[v]) {
          q.push(v);
          vis[v] = 1;
        }
      }
    }
  }
}
int vis_edge[maxn * 2];
int main() {
  while (scanf("%d%d", &N, &M) != EOF) {
    init();
    int u, v, type;
    for (int i = 1; i <= M; i++) {
      scanf("%d%d%d", &u, &v, &type);
      add_edge(u, v, type, i);
      add_edge(v, u, type, i);
    }
    memset(id, 0, sizeof(id));
    SPFA(1, N);
    memset(vis, 0, sizeof(vis));
    memset(vis_edge, 0, sizeof(vis_edge));
    u = N;
    while (pre[u] != -1) {
      vis_edge[id[u]] = 1;
      u = pre[u];
    }
    int ans = 0;
    for (int u = 1; u <= N; ++u) {
      for (int i = head[u]; ~i; i = edge[i].next) {
        int v = edge[i].v;
        if (!vis_edge[edge[i].id] && edge[i].type && !vis[edge[i].id]) {
          ++ans;
          vis[edge[i].id] = 1;
        } else if (vis_edge[edge[i].id] && !edge[i].type && !vis[edge[i].id]) {
          ++ans;
          vis[edge[i].id] = 1;
        }
      }
    }
    memset(vis, 0, sizeof(vis));
    printf("%d\n", ans);
    for (int u = 1; u <= N; ++u) {
      for (int i = head[u]; ~i; i = edge[i].next) {
        int v = edge[i].v;
        if (vis[edge[i].id]) {
          continue;
        }
        if (!vis_edge[edge[i].id] && edge[i].type) {
          printf("%d %d 0\n", u, v);
          vis[edge[i].id] = 1;
        } else if (vis_edge[edge[i].id] && !edge[i].type) {
          printf("%d %d 1\n", u, v);
          vis[edge[i].id] = 1;
        }
      }
    }
  }
  return 0;
}
