#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<pair<pair<int, int>, int> > > M(
      n + 1, vector<pair<pair<int, int>, int> >());
  int cmalo = 0;
  for (int i = 0; i < m; i++) {
    int u, v, z;
    cin >> u >> v >> z;
    cmalo += (z == 0);
    M[u].push_back(pair<pair<int, int>, int>(pair<int, int>(1, abs(z - 1)), v));
    M[v].push_back(pair<pair<int, int>, int>(pair<int, int>(1, abs(z - 1)), u));
  }
  vector<int> dist(n + 1, INT_MAX);
  dist[1] = 0;
  vector<int> cos(n + 1, INT_MAX);
  cos[1] = 0;
  vector<pair<int, int> > parent(n + 1, pair<int, int>(0, 0));
  priority_queue<pair<pair<int, int>, int>, vector<pair<pair<int, int>, int> >,
                 greater<pair<pair<int, int>, int> > >
      pq;
  pq.push(pair<pair<int, int>, int>(pair<int, int>(0, 0), 1));
  while (!pq.empty()) {
    pair<pair<int, int>, int> p = pq.top();
    pq.pop();
    int d1 = p.first.first, d2 = p.first.second, u = p.second;
    if (d1 > dist[u]) continue;
    if (d1 == dist[u] && d2 > cos[u]) continue;
    for (int j = 0; j < M[u].size(); j++) {
      pair<pair<int, int>, int> v = M[u][j];
      int v1 = v.first.first, v2 = v.first.second, v3 = v.second;
      if (dist[v3] > dist[u] + v1 ||
          (dist[v3] == dist[u] + v1 && cos[v3] > cos[u] + v2)) {
        parent[v3] = pair<int, int>(u, v2);
        dist[v3] = dist[u] + v1;
        cos[v3] = cos[u] + v2;
        pq.push(
            pair<pair<int, int>, int>(pair<int, int>(dist[v3], cos[v3]), v3));
      }
    }
  }
  int l = dist[n], c = cos[n];
  cout << m - l - (cmalo - c) + c << "\n";
  int s = n;
  set<pair<int, int> > S;
  while (s != 1) {
    int e = parent[s].first, z = parent[s].second;
    S.insert(minmax(s, e));
    if (z == 1) {
      cout << s << " " << e << " " << 1 << "\n";
    }
    s = e;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < M[i].size(); j++) {
      int u = i, v = M[i][j].second, z = M[i][j].first.second;
      if (S.count(minmax(u, v))) continue;
      S.insert(minmax(u, v));
      if (z == 0) cout << u << " " << v << " " << 0 << "\n";
    }
  }
  return 0;
}
