#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > g[100000], good_edges;
int n, m, Z;
void bfs() {
  vector<pair<int, int> > dist(n, pair<int, int>(0x3f3f3f3f, 0x3f3f3f3f));
  vector<int> p(n, -1);
  vector<int> ez(n, -1);
  dist[0].first = 0;
  dist[0].second = m - Z;
  queue<int> Q;
  Q.push(0);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int i = 0; i < g[u].size(); i++) {
      int v = g[u][i].first;
      int z = g[u][i].second;
      int dz = dist[u].second;
      if (z)
        dz--;
      else
        dz++;
      if (dist[u].first + 1 < dist[v].first) {
        dist[v].first = dist[u].first + 1;
        dist[v].second = dz;
        p[v] = u;
        ez[v] = z;
        Q.push(v);
      } else if (dist[u].first + 1 == dist[v].first && dist[v].second > dz) {
        dist[v].second = dz;
        p[v] = u;
        ez[v] = z;
        Q.push(v);
      }
    }
  }
  set<pair<int, int> > path;
  vector<pair<int, pair<int, int> > > edges_aff;
  for (int w = n - 1; p[w] != -1; w = p[w]) {
    if (!ez[w]) {
      edges_aff.push_back(make_pair(1, make_pair(w, p[w])));
    }
    path.insert(make_pair(w, p[w]));
    path.insert(make_pair(p[w], w));
  }
  for (int i = 0; i < good_edges.size(); i++) {
    if (path.find(good_edges[i]) == path.end()) {
      edges_aff.push_back(make_pair(0, good_edges[i]));
    }
  }
  cout << edges_aff.size() << "\n";
  for (int i = 0; i < edges_aff.size(); i++)
    cout << edges_aff[i].second.first + 1 << " "
         << 1 + edges_aff[i].second.second << " " << edges_aff[i].first << "\n";
}
int main() {
  cin >> n >> m;
  for (int(i) = (0); (i) < (m); ++(i)) {
    int u, v, z;
    cin >> u >> v >> z;
    u--;
    v--;
    g[u].push_back(make_pair(v, z));
    g[v].push_back(make_pair(u, z));
    Z += z;
    if (z) good_edges.push_back(make_pair(u, v));
  }
  bfs();
  return 0;
}
