#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
struct edge {
  int a, b, c;
};
int n, m;
vector<int> g[100100];
vector<edge> e;
long long d[100100];
set<pair<long long, long long> > s;
int par[100100];
int u[100100 * 2];
void dyikstr() {
  for (int i = 0; i < n; ++i) d[i] = 100000000000000007;
  par[0] = 0;
  d[0] = 0;
  s.insert(make_pair(0, 0));
  while (!s.empty()) {
    pair<int, int> p = *s.begin();
    s.erase(s.begin());
    int v = p.second;
    for (int i = 0; i < g[v].size(); ++i) {
      int id = g[v][i];
      int to = e[id].b;
      int w = e[id].c;
      if (d[to] > d[v] + w) {
        s.erase(make_pair(d[to], to));
        d[to] = d[v] + w;
        par[to] = id;
        s.insert(make_pair(d[to], to));
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int x, y, z;
    cin >> x >> y >> z;
    x--;
    y--;
    long long q = m + 1;
    if (!z) q++;
    edge e1;
    e1.a = x;
    e1.b = y;
    e1.c = q;
    g[x].push_back(e.size());
    e.push_back(e1);
    e1.b = x;
    e1.a = y;
    e1.c = q;
    g[y].push_back(e.size());
    e.push_back(e1);
  }
  dyikstr();
  int v = n - 1;
  int ans = 0;
  while (v) {
    int id = par[v];
    u[id] = 1;
    u[id ^ 1] = 1;
    if (e[id].c == m + 1) ans++;
    v = e[id].a;
  }
  int cnt = 0;
  for (int i = 0; i < e.size(); i += 2) {
    if (u[i] && e[i].c == m + 1) {
      continue;
    }
    int nv = m + 1;
    if (!u[i]) nv = m + 2;
    if (e[i].c == nv) continue;
    cnt++;
  }
  printf("%d\n", cnt);
  for (int i = 0; i < e.size(); i += 2) {
    if (u[i] && e[i].c == m + 1) {
      continue;
    }
    int nv = m + 1;
    if (!u[i]) nv = m + 2;
    if (e[i].c == nv) continue;
    printf("%d %d ", e[i].a + 1, e[i].b + 1);
    if (u[i])
      printf("%d\n", 1);
    else
      printf("%d\n", 0);
  }
  return 0;
}
