#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:2560000000000")
#pragma warning(disable : 4996)
using namespace std;
set<pair<int, int> > st;
vector<int> gr[100011];
long long d[100011];
long long r[100011];
long long p[100011];
bool us[100011];
int main() {
  long long n, m;
  cin >> n >> m;
  fill(d + 1, d + 100009, 1111111111);
  memset(r, 0, sizeof(r));
  set<pair<pair<int, int>, int> > ans;
  for (int i = 1; i <= m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    gr[x].push_back(y);
    gr[y].push_back(x);
    if (z == 1) ans.insert(make_pair(make_pair(min(x, y), max(x, y)), 0));
    if (!z) st.insert(make_pair(min(x, y), max(x, y)));
  }
  p[1] = -1;
  d[1] = 0;
  queue<int> q;
  r[1] = 0;
  q.push(1);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    if (us[v])
      continue;
    else {
      us[v] = 1;
    }
    for (int i = 0; i < gr[v].size(); i++) {
      int to = gr[v][i];
      bool b = (st.find(make_pair(min(v, to), max(v, to))) != st.end());
      if (d[to] > d[v] + 1 || (d[to] == d[v] + 1 && r[to] > r[v] + b)) {
        d[to] = d[v] + 1;
        r[to] = r[v] + b;
        p[to] = v;
        q.push(to);
      }
    }
  }
  int v = n;
  do {
    int u = p[v];
    if (st.find(make_pair(min(u, v), max(u, v))) == st.end())
      ans.erase(make_pair(make_pair(min(u, v), max(u, v)), 0));
    else
      ans.insert(make_pair(make_pair(min(u, v), max(u, v)), 1));
    v = p[v];
  } while (v != 1);
  cout << ans.size() << endl;
  for (set<pair<pair<int, int>, int> >::iterator it = ans.begin();
       it != ans.end(); ++it)
    cout << (*it).first.first << ' ' << (*it).first.second << ' '
         << (*it).second << endl;
}
