#include <bits/stdc++.h>
using namespace std;
int n, m;
int work[100100];
int x[100100];
int y[100100];
int ok[100100];
vector<pair<int, int> > G[100100];
int dist[100100];
int dist2[100100];
int dist3[100100];
int dad[100100];
const int INF = 1e8;
void fs() {
  queue<int> q;
  q.push(1);
  for (int i = (0); i < (n + 1); i++) dist[i] = INF;
  dist[1] = 0;
  while (((int)q.size())) {
    int v = q.front();
    q.pop();
    for (typeof(G[v].begin()) it = G[v].begin(); it != G[v].end(); ++it) {
      if (dist[it->first] > dist[v] + 1) {
        dist[it->first] = dist[v] + 1;
        q.push(it->first);
      }
    }
  }
}
void fs2() {
  queue<int> q;
  q.push(n);
  for (int i = (0); i < (n + 1); i++) dist2[i] = INF;
  dist2[n] = 0;
  while (((int)q.size())) {
    int v = q.front();
    q.pop();
    for (typeof(G[v].begin()) it = G[v].begin(); it != G[v].end(); ++it) {
      if (dist2[it->first] > dist2[v] + 1) {
        dist2[it->first] = dist2[v] + 1;
        q.push(it->first);
      }
    }
  }
}
void fs3() {
  deque<int> q;
  for (int i = (0); i < (n + 1); i++) dist3[i] = INF, dad[i] = -1;
  dist3[1] = 0;
  q.push_back(1);
  while (((int)q.size())) {
    int v = q.front();
    q.pop_front();
    for (typeof(G[v].begin()) it = G[v].begin(); it != G[v].end(); ++it) {
      if (ok[it->second]) {
        int nd = dist3[v] + !work[it->second];
        if (dist3[it->first] > nd) {
          dist3[it->first] = nd;
          dad[it->first] = it->second;
          if (!work[it->second])
            q.push_back(it->first);
          else
            q.push_front(it->first);
        }
      }
    }
  }
}
bool path[100100];
void rec(int v) {
  if (dad[v] == -1) return;
  path[dad[v]] = true;
  rec(x[dad[v]] ^ y[dad[v]] ^ v);
}
int main() {
  while (cin >> n >> m) {
    for (int i = (0); i < (m); i++) {
      scanf("%d%d%d", x + i, y + i, work + i);
      G[x[i]].push_back(pair<int, int>(y[i], i));
      G[y[i]].push_back(pair<int, int>(x[i], i));
    }
    fs();
    fs2();
    for (int i = (0); i < (m); i++) {
      if (dist[x[i]] + 1 + dist2[y[i]] == dist[n] ||
          dist2[x[i]] + 1 + dist[y[i]] == dist[n]) {
        ok[i] = true;
      } else
        ok[i] = false;
    }
    fs3();
    rec(n);
    vector<int> r;
    for (int i = (0); i < (m); i++)
      if (path[i] && !work[i])
        r.push_back(i);
      else if (!path[i] && work[i])
        r.push_back(i);
    cout << ((int)r.size()) << endl;
    for (int i = (0); i < (((int)r.size())); i++)
      cout << x[r[i]] << ' ' << y[r[i]] << ' ' << (path[r[i]] ? 1 : 0) << "\n";
  }
  return 0;
}
