#include <bits/stdc++.h>
using namespace std;
struct data {
  int u, cost, unused;
  data(int x, int y, int z) {
    u = x;
    cost = y;
    unused = z;
  }
  bool operator<(const data &d) const {
    if (cost == d.cost)
      return unused > d.unused;
    else
      return cost > d.cost;
  }
};
struct neww {
  int cost, unused;
} dist[100100];
struct again {
  int u, v, t;
} edge[100100];
int n, e, visited[100100], parent[100010], used[100100];
vector<int> A[100100], road[100100];
priority_queue<struct data> q;
struct data dijkstra() {
  int i, j, k, m;
  struct data c(1, 0, 0), t(n, 0, 0);
  for (i = 0; i <= n; i++) {
    visited[i] = false;
    parent[i] = -1;
    used[i] = false;
    dist[i].cost = dist[i].unused = 1 << 30;
  }
  q.push(c);
  while (!q.empty()) {
    c = q.top();
    q.pop();
    if (visited[c.u] == true) continue;
    visited[c.u] = true;
    if (c.u == n) return c;
    m = A[c.u].size();
    for (i = 0; i < m; i++) {
      t.u = A[c.u][i];
      t.cost = c.cost + 1;
      t.unused = c.unused + 1 - road[c.u][i];
      if (visited[t.u]) continue;
      if ((dist[t.u].cost > t.cost) ||
          (dist[t.u].cost == t.cost && dist[t.u].unused > t.unused)) {
        parent[t.u] = c.u;
        dist[t.u].cost = t.cost;
        dist[t.u].unused = t.unused;
        q.push(t);
      }
    }
  }
}
int main() {
  int i, j, k, sum = 0;
  scanf("%d%d", &n, &e);
  for (i = 0; i < e; i++) {
    scanf("%d%d%d", &edge[i].u, &edge[i].v, &edge[i].t);
    A[edge[i].u].push_back(edge[i].v);
    A[edge[i].v].push_back(edge[i].u);
    road[edge[i].u].push_back(edge[i].t);
    road[edge[i].v].push_back(edge[i].t);
    sum += edge[i].t;
  }
  struct data c = dijkstra();
  printf("%d\n", c.unused + sum - (c.cost - c.unused));
  i = n;
  while (i != -1) {
    used[i] = true;
    i = parent[i];
  }
  for (i = 0; i < e; i++) {
    if (edge[i].t == 1 && (!used[edge[i].u] || !used[edge[i].v]))
      printf("%d %d %d\n", edge[i].u, edge[i].v, 0);
    if (edge[i].t == 0 && (used[edge[i].u] && used[edge[i].v]))
      printf("%d %d %d\n", edge[i].u, edge[i].v, 1);
  }
  return 0;
}
