#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long llinf = 1ll * inf * inf;
const double eps = 1e-12;
int n, m;
const int N = 1e5 + 10;
vector<int> adj[N], good[N];
pair<int, int> s[N];
int dad[N];
int main() {
  scanf("%d%d", &n, &m);
  int cnt_good = 0;
  for (int i = 0; i < int(m); ++i) {
    int u, v, b;
    scanf("%d%d%d", &u, &v, &b);
    adj[u].push_back(v);
    good[u].push_back(b);
    adj[v].push_back(u);
    good[v].push_back(b);
    cnt_good += b;
  }
  for (int i = 1; i <= int(n); ++i) s[i] = make_pair(inf, inf);
  priority_queue<tuple<int, int, int, int>, vector<tuple<int, int, int, int> >,
                 greater<tuple<int, int, int, int> > >
      q;
  q.emplace(0, 0, 1, -1);
  s[1] = make_pair(0, 0);
  dad[1] = -1;
  while (!q.empty()) {
    tuple<int, int, int, int> curs = q.top();
    q.pop();
    int d, x, p, u;
    tie(d, x, u, p) = curs;
    if (make_pair(d, x) != s[u]) continue;
    for (int i = 0; i < adj[u].size(); ++i)
      if (adj[u][i] != p) {
        int nxtd = 1 + d;
        int nxtx = x + int(good[u][i] == 0);
        int nxtu = adj[u][i];
        int nxtp = u;
        if (make_pair(nxtd, nxtx) < s[adj[u][i]]) {
          s[adj[u][i]] = make_pair(nxtd, nxtx);
          q.emplace(nxtd, nxtx, nxtu, nxtd);
          dad[adj[u][i]] = u;
        }
      }
  }
  printf("%d\n", cnt_good - s[n].first + 2 * s[n].second);
  set<pair<int, int> > vis;
  for (int u = n; dad[u] != -1; u = dad[u]) {
    int prevu = dad[u];
    vis.emplace(prevu, u);
    for (int i = 0; i < adj[prevu].size(); ++i) {
      int v = adj[prevu][i];
      if (v == u) {
        if (good[prevu][i] == 0) printf("%d %d 1\n", prevu, u);
      }
    }
  }
  for (int u = 1; u <= n; ++u) {
    for (int i = 0; i < adj[u].size(); ++i) {
      int v = adj[u][i];
      if (good[u][i] == 1 && vis.count(make_pair(u, v)) == 0 &&
          vis.count(make_pair(v, u)) == 0)
        printf("%d %d 0\n", u, v), vis.emplace(u, v);
    }
  }
  return 0;
}
