#include <bits/stdc++.h>
using namespace std;
const long long size = 200007;
const long long modulo = 1000000007;
const int oo = 1e9;
const double EPS = 1e-2;
const double PI = acos(-1.0);
int passable[size];
int was[size], previ[size], d[size];
vector<vector<pair<int, int> > > g;
int main() {
  int n, m;
  cin >> n >> m;
  g.resize(n);
  map<pair<int, int>, int> p;
  int t_pas = 0, t_impas = 0;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    --a;
    --b;
    g[a].push_back(make_pair(b, c));
    g[b].push_back(make_pair(a, c));
    p[make_pair(a, b)] = p[make_pair(b, a)] = c;
    if (c == 0)
      ++t_impas;
    else
      ++t_pas;
  }
  queue<int> q;
  q.push(0);
  for (int i = 0; i < n; i++) d[i] = 77777777;
  d[0] = 0;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    if (v == n - 1) break;
    was[v] = 1;
    for (int i = 0; i < g[v].size(); i++) {
      int to = g[v][i].first;
      if (d[v] + 1 > d[to]) continue;
      int pas = g[v][i].second;
      if (d[v] + 1 < d[to]) {
        d[to] = d[v] + 1;
        q.push(to);
        passable[to] = passable[v] + pas;
        previ[to] = v;
      } else if (d[v] + 1 == d[to]) {
        if (passable[to] < passable[v] + pas) {
          passable[to] = passable[v] + pas;
          previ[to] = v;
        }
      }
    }
  }
  int im = t_pas - passable[n - 1];
  int ans = d[n - 1] - passable[n - 1] + im;
  cout << ans << endl;
  set<pair<int, int> > s;
  int cur = n - 1;
  while (cur > 0) {
    int v = previ[cur];
    if (p[make_pair(v, cur)] == 0) {
      cout << v + 1 << ' ' << cur + 1 << ' ' << 1 << endl;
    }
    s.insert(make_pair(v, cur));
    s.insert(make_pair(cur, v));
    cur = v;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < g[i].size(); j++) {
      int to = g[i][j].first;
      if (s.count(make_pair(i, to)) == 1) continue;
      if (g[i][j].second == 1) {
        cout << i + 1 << ' ' << to + 1 << ' ' << 0 << endl;
      }
      s.insert(make_pair(i, to));
      s.insert(make_pair(to, i));
    }
  return 0;
}
