#include <bits/stdc++.h>
using namespace std;
struct st {
  int node;
  int val;
  int con;
  bool operator<(const st &b) const { return val > b.val; }
};
priority_queue<st> Q;
bool bi[100005];
int N;
vector<int> G[100005];
vector<int> v[100005];
vector<int> w[100005];
vector<int> W[100005];
int p[100005];
int key[100005];
int inact;
map<pair<int, int>, bool> M;
void dij() {
  int a, b, c, d, e, x, y, z, n;
  for (a = 0; a <= N; a++) {
    key[a] = 1000000;
    bi[a] = false;
  }
  st k;
  k.node = 1;
  k.val = 0;
  Q.push(k);
  key[1] = 0;
  while (!Q.empty()) {
    k = Q.top();
    Q.pop();
    b = k.node;
    if (bi[b]) continue;
    bi[b] = true;
    for (a = 0; a < v[b].size(); a++) {
      c = v[b][a];
      if (bi[c]) continue;
      if (key[b] + 1 >= key[c]) continue;
      key[c] = key[b] + 1;
      k.node = c;
      k.val = key[c];
      p[c] = b;
      Q.push(k);
    }
  }
}
queue<int> q;
void build_dag() {
  int a, b, c, d, e, x, y, z;
  for (a = 0; a <= N; a++) bi[a] = false;
  bi[N] = true;
  q.push(N);
  while (!q.empty()) {
    b = q.front();
    q.pop();
    for (a = 0; a < v[b].size(); a++) {
      c = v[b][a];
      if (key[c] + 1 == key[b]) {
        G[c].push_back(b);
        W[c].push_back(w[b][a]);
        if (!bi[c]) {
          q.push(c);
          bi[c] = true;
        }
      }
    }
  }
}
void find_path(int ec) {
  int a, b, c, d, e, x, y, z, n;
  for (a = 0; a <= N; a++) {
    key[a] = 10000000;
    bi[a] = false;
  }
  while (!Q.empty()) Q.pop();
  st k;
  k.node = 1;
  k.val = 0;
  Q.push(k);
  key[1] = 0;
  pair<int, int> pi;
  while (!Q.empty()) {
    k = Q.top();
    Q.pop();
    b = k.node;
    if (bi[b]) continue;
    bi[b] = true;
    for (a = 0; a < G[b].size(); a++) {
      c = G[b][a];
      if (bi[c]) continue;
      if (W[b][a])
        z = 0;
      else
        z = 1;
      if (key[c] <= key[b] + z) continue;
      key[c] = key[b] + z;
      k.node = c;
      k.val = key[c];
      k.con = W[b][a];
      p[c] = b;
      Q.push(k);
    }
  }
}
void recur(int i) {
  if (!p[i]) return;
  pair<int, int> pi;
  pi.first = min(i, p[i]);
  pi.second = max(i, p[i]);
  M[pi] = true;
  recur(p[i]);
}
int ans[100005][3];
int ac;
int main() {
  int a, b, c, d, e, x, y, z;
  scanf("%d %d", &N, &z);
  inact = 0;
  for (a = 0; a < z; a++) {
    scanf("%d %d %d", &b, &c, &d);
    v[b].push_back(c);
    v[c].push_back(b);
    w[b].push_back(d);
    w[c].push_back(d);
    if (!d) inact++;
  }
  M.clear();
  dij();
  build_dag();
  find_path(z);
  recur(N);
  pair<int, int> pi;
  ac = 0;
  for (a = 1; a <= N; a++) {
    for (b = 0; b < v[a].size(); b++) {
      c = v[a][b];
      pi.first = min(a, c);
      pi.second = max(a, c);
      if (M[pi]) {
        if (!w[a][b] && a < c) {
          ans[ac][0] = a;
          ans[ac][1] = c;
          ans[ac][2] = 1;
          ac++;
        }
      } else {
        if (w[a][b] && a < c) {
          ans[ac][0] = a;
          ans[ac][1] = c;
          ans[ac][2] = 0;
          ac++;
        }
      }
    }
  }
  cout << ac << endl;
  for (a = 0; a < ac; a++)
    cout << ans[a][0] << " " << ans[a][1] << " " << ans[a][2] << endl;
  return 0;
}
