#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, z, cnt, c[100100], d[100100];
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    pq;
vector<pair<int, pair<int, int> > > graph[100100];
vector<pair<int, pair<int, int> > > edge, v;
bool mark[100100];
pair<int, int> p[100100];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) d[i] = 1e9;
  for (int i = 0; i < m; i++) {
    cin >> x >> y >> z;
    graph[x].push_back(make_pair(y, make_pair(z, i)));
    graph[y].push_back(make_pair(x, make_pair(z, i)));
    edge.push_back(make_pair(z, make_pair(x, y)));
    if (z) cnt++;
  }
  d[1] = 0;
  pq.push(make_pair(0, 1));
  while (!pq.empty()) {
    x = pq.top().second;
    pq.pop();
    for (int i = 0; i < graph[x].size(); i++) {
      y = graph[x][i].first;
      if (d[x] + 1 <= d[y]) {
        if (d[x] + 1 < d[y]) p[y] = make_pair(x, graph[x][i].second.second);
        d[y] = d[x] + 1;
        if (c[x] + graph[x][i].second.first > c[y]) {
          p[y] = make_pair(x, graph[x][i].second.second);
          c[y] = c[x] + graph[x][i].second.first;
        }
        pq.push(make_pair(d[y], y));
      }
    }
  }
  x = n;
  while (x != 1) {
    y = x;
    x = p[y].first;
    if (edge[p[y].second].first == 0) v.push_back(edge[p[y].second]);
    mark[p[y].second] = 1;
  }
  for (int i = 0; i < edge.size(); i++) {
    if (!mark[i] && edge[i].first) v.push_back(edge[i]);
  }
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i].second.first << " " << v[i].second.second << " "
         << (!v[i].first) << endl;
  }
  return 0;
}
