#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int MAXE = 200005;
const int INF = 0x3f3f3f3f;
struct Edge {
  int v, c, n;
  Edge() {}
  Edge(int v, int c, int n) : v(v), c(c), n(n) {}
};
struct Node {
  int d, x, y;
  Node() {}
  Node(int d, int x, int y) : d(d), x(x), y(y) {}
  Node operator+(const Node a) const { return Node(d + a.d, x + a.x, y + a.y); }
  bool operator<(const Node& a) const {
    if (d != a.d) return d < a.d;
    return x + y < a.x + a.y;
  }
};
struct Road {
  int u, v, c;
  Road() {}
  Road(int u, int v, int c) : u(u), v(v), c(c) {}
};
Road road[MAXN];
Edge E[MAXE];
int H[MAXN], cntE;
int n, m;
int vis[MAXN];
Node d[MAXN];
int pre[MAXN];
int Q[MAXN], head, tail;
int num;
void clear() {
  num = 0;
  cntE = 0;
  memset(H, -1, sizeof H);
}
void addedge(int u, int v, int c) {
  E[cntE] = Edge(v, c, H[u]);
  H[u] = cntE++;
}
void spfa() {
  head = tail = 0;
  memset(vis, 0, sizeof vis);
  memset(d, INF, sizeof d);
  d[1] = Node(0, num, 0);
  Q[tail++] = 1;
  while (head != tail) {
    int u = Q[head++];
    if (head == MAXN) head = 0;
    vis[u] = 0;
    for (int i = H[u]; ~i; i = E[i].n) {
      int v = E[i].v;
      Node tmp = d[u] + Node(1, -E[i].c, !E[i].c);
      if (tmp < d[v]) {
        d[v] = tmp;
        pre[v] = i;
        if (!vis[v]) {
          Q[tail++] = v;
          if (tail == MAXN) tail = 0;
          vis[v] = 1;
        }
      }
    }
  }
  memset(vis, 0, sizeof vis);
  for (int i = n; i != 1; i = E[pre[i] ^ 1].v) {
    vis[pre[i] >> 1] = 1;
  }
  int cnt = 0;
  for (int i = (0); i < (m); ++i) {
    if (vis[i] == 0 && road[i].c == 1) ++cnt;
    if (vis[i] == 1 && road[i].c == 0) ++cnt;
  }
  printf("%d\n", cnt);
  for (int i = (0); i < (m); ++i) {
    if (vis[i] == 0 && road[i].c == 1)
      printf("%d %d %d\n", road[i].u, road[i].v, 0);
    if (vis[i] == 1 && road[i].c == 0)
      printf("%d %d %d\n", road[i].u, road[i].v, 1);
  }
};
void solve() {
  int u, v, c;
  clear();
  for (int i = (0); i < (m); ++i) {
    scanf("%d%d%d", &u, &v, &c);
    road[i] = Road(u, v, c);
    addedge(u, v, c);
    addedge(v, u, c);
    num += c;
  }
  spfa();
}
int main() {
  while (~scanf("%d%d", &n, &m)) solve();
  return 0;
}
