#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
vector<pair<int, int> > G[maxn];
int n, m;
int F[maxn];
int cnt[maxn];
deque<int> q;
pair<int, int> tvet[maxn];
void dij() {
  for (int i = 1; i <= n; i++) F[i] = cnt[i] = maxn;
  F[n] = cnt[n] = 0;
  tvet[n].first = -1;
  q.push_back(n);
  while (q.empty() == 0) {
    int u = q.front();
    q.pop_front();
    for (vector<pair<int, int> >::iterator id = G[u].begin(); id != G[u].end();
         id++) {
      pair<int, int> wat = *id;
      int v = wat.first;
      int work = wat.second;
      if (F[v] > F[u] + 1) {
        tvet[v].first = u;
        tvet[v].second = work;
        F[v] = F[u] + 1;
        cnt[v] = cnt[u] + (work == 1 ? 0 : 1);
        q.push_back(v);
      } else if (F[v] == F[u] + 1) {
        if (cnt[v] > cnt[u] + (work == 1 ? 0 : 1)) {
          cnt[v] = cnt[u] + (work == 1 ? 0 : 1);
          tvet[v].first = u;
          tvet[v].second = work;
          q.push_back(v);
        }
      }
    }
  }
}
struct nani {
  int u, v, z;
};
bool cmp(nani A, nani B) {
  if (A.u == B.u) {
    if (A.v == B.v) {
      return A.z < B.z;
    } else
      return A.v < B.v;
  } else
    return A.u < B.u;
}
vector<nani> q1, q2;
void road(int id) {
  if (tvet[id].first == -1) return;
  int v = tvet[id].first;
  int work = tvet[id].second;
  if (work == 0) {
    cout << id << " " << v << " " << 1 << endl;
  } else {
    if (id < v)
      q2.push_back({id, v, work});
    else
      q2.push_back({v, id, work});
  }
  road(v);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> m;
  int cnt2 = 0;
  for (int i = 1; i <= m; i++) {
    int u, v, z;
    cin >> u >> v >> z;
    cnt2 += z;
    if (z == 1) {
      if (u < v)
        q1.push_back({u, v, z});
      else
        q1.push_back({v, u, z});
    }
    G[u].push_back(pair<int, int>(v, z));
    G[v].push_back(pair<int, int>(u, z));
  }
  dij();
  cout << cnt[1] + cnt2 - (F[1] - cnt[1]) << "\n";
  road(1);
  sort(q1.begin(), q1.end(), cmp);
  sort(q2.begin(), q2.end(), cmp);
  int dem1 = 0;
  for (vector<nani>::iterator id = q1.begin(); id != q1.end(); id++) {
    nani hehe = *id;
    if (q2.size() > 0) {
      if (q2[dem1].u == hehe.u && q2[dem1].v == hehe.v && q2[dem1].z == hehe.z)
        dem1++;
      else
        cout << hehe.u << " " << hehe.v << " " << 0 << "\n";
    } else
      cout << hehe.u << " " << hehe.v << " " << 0 << "\n";
  }
}
