#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.1415926535897932384626433832795028;
long long n, m;
vector<pair<long long, long long> > ve[100010];
vector<pair<long long, pair<long long, long long> > > a;
long long disStart[100010], disEnd[100010];
void solve() {
  for (long long i = 0; i <= n; i++) {
    disStart[i] = disEnd[i] = 1e9;
  }
  queue<long long> qe;
  qe.push(1);
  disStart[1] = 0;
  while (!qe.empty()) {
    long long x = qe.front();
    qe.pop();
    for (long long i = 0; i < ve[x].size(); i++) {
      long long to = ve[x][i].first;
      if (disStart[to] > disStart[x] + 1) {
        qe.push(to);
        disStart[to] = disStart[x] + 1;
      }
    }
  }
  qe.push(n);
  disEnd[n] = 0;
  while (!qe.empty()) {
    long long x = qe.front();
    qe.pop();
    for (long long i = 0; i < ve[x].size(); i++) {
      long long to = ve[x][i].first;
      if (disEnd[to] > disEnd[x] + 1) {
        qe.push(to);
        disEnd[to] = disEnd[x] + 1;
      }
    }
  }
}
long long cnt[100010];
long long par[100010];
long long path[100010];
void solve2() {
  for (long long i = 0; i <= n; i++) {
    cnt[i] = -1;
    par[i] = i;
    path[i] = i;
  }
  queue<long long> Qe;
  Qe.push(1);
  cnt[1] = 0;
  while (!Qe.empty()) {
    long long node = Qe.front();
    Qe.pop();
    for (long long i = 0; i < ve[node].size(); i++) {
      long long to = ve[node][i].first;
      long long w = ve[node][i].second;
      if (disStart[to] + disEnd[to] == disStart[n] &&
          disStart[node] + disEnd[to] + 1 == disStart[n]) {
        if (cnt[to] < cnt[node] + w) {
          cnt[to] = cnt[node] + w;
          Qe.push(to);
          par[to] = node;
        }
      }
    }
  }
  long long node = n;
  while (node != 1) {
    path[node] = par[node];
    node = par[node];
  }
}
int main() {
  ;
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long x, y, z;
    cin >> x >> y >> z;
    ve[x].push_back({y, z});
    ve[y].push_back({x, z});
    a.push_back({x, {y, z}});
  }
  solve();
  solve2();
  vector<pair<long long, pair<long long, long long> > > ans;
  for (long long i = 0; i < m; i++) {
    long long x = a[i].first;
    long long y = a[i].second.first;
    long long z = a[i].second.second;
    if (path[x] == y || path[y] == x) {
      if (z == 0) {
        ans.push_back({x, {y, 1}});
      }
    } else {
      if (z) ans.push_back({x, {y, 0}});
    }
  }
  cout << ans.size() << endl;
  for (long long i = 0; i < ans.size(); i++) {
    cout << ans[i].first << " " << ans[i].second.first << " "
         << ans[i].second.second << endl;
  }
}
