#include <bits/stdc++.h>
using namespace std;
int N, M, A, B, Z;
vector<pair<int, int> > G[100000];
pair<int, int> d[100000];
int prevv[100000];
int preve[100000];
int a[100000], b[100000], z[100000];
bool used[100000];
int main() {
  scanf("%d%d", &N, &M);
  for (int(i) = 0; (i) < (M); (i)++) {
    scanf("%d%d%d", &A, &B, &Z);
    A--, B--;
    a[i] = A, b[i] = B, z[i] = Z;
    G[A].push_back(make_pair(Z * M + i, B)),
        G[B].push_back(make_pair(Z * M + i, A));
  }
  priority_queue<pair<pair<int, int>, int>, vector<pair<pair<int, int>, int> >,
                 greater<pair<pair<int, int>, int> > >
      q;
  for (int(i) = 0; (i) < (N); (i)++) d[i] = make_pair((1 << 29), (1 << 29));
  d[0] = make_pair(0, 0);
  q.push(make_pair(d[0], 0));
  memset((prevv), (-1), sizeof(prevv));
  memset((preve), (-1), sizeof(preve));
  while (!q.empty()) {
    pair<int, int> da = q.top().first;
    int v = q.top().second;
    q.pop();
    for (int(i) = 0; (i) < (G[v].size()); (i)++) {
      pair<int, int> nd =
          make_pair(da.first + 1, da.second + (G[v][i].first < M));
      if (d[G[v][i].second] > nd) {
        d[G[v][i].second] = nd;
        q.push(make_pair(nd, G[v][i].second));
        prevv[G[v][i].second] = v;
        preve[G[v][i].second] = i;
      }
    }
  }
  int v = N - 1;
  while (v != 0) {
    used[G[prevv[v]][preve[v]].first % M] = true;
    v = prevv[v];
  }
  int as = 0;
  for (int(i) = 0; (i) < (M); (i)++) {
    if (used[i] && z[i] == 0) as++;
    if (!used[i] && z[i] == 1) as++;
  }
  printf("%d\n", as);
  for (int(i) = 0; (i) < (M); (i)++) {
    a[i]++, b[i]++;
    z[i] = 1 - z[i];
    if (used[i] && z[i] == 1) printf("%d %d %d\n", a[i], b[i], z[i]);
    if (!used[i] && z[i] == 0) printf("%d %d %d\n", a[i], b[i], z[i]);
  }
}
