#include <bits/stdc++.h>
using namespace std;
const long long maxx = 1e5 + 20, inf = 1e13 + 2;
vector<pair<long long, long long> > adj[maxx];
set<pair<long long, long long> > s;
long long n, d[maxx], m;
pair<long long, long long> dad[maxx];
pair<pair<long long, long long>, long long> e[maxx];
bool mark[maxx];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long x, y, z;
    cin >> x >> y >> z;
    x--, y--;
    e[i] = make_pair(make_pair(x, y), z);
    adj[x].push_back(make_pair(y, i));
    adj[y].push_back(make_pair(x, i));
  }
  fill(d, d + maxx, inf);
  s.insert(make_pair(0, 0));
  d[0] = 0;
  while (s.size()) {
    pair<long long, long long> x = *s.begin();
    s.erase(s.begin());
    for (pair<long long, long long> y : adj[x.second]) {
      long long e1 = y.first, e2 = y.second;
      long long tool = maxx + (1 - e[e2].second);
      if (d[e1] > tool + d[x.second]) {
        s.erase(make_pair(d[e1], e1));
        d[e1] = tool + d[x.second];
        s.insert(make_pair(d[e1], e1));
        dad[e1] = make_pair(x.second, e2);
      }
    }
  }
  long long k = n - 1, t = 0;
  while (k != 0) {
    mark[dad[k].second] = true;
    k = dad[k].first;
  }
  for (int i = 0; i < m; i++) {
    if (mark[i] && e[i].second == 0 || !mark[i] && e[i].second == 1) t++;
  }
  cout << t << '\n';
  for (int i = 0; i < m; i++) {
    if (mark[i] && e[i].second == 0 || !mark[i] && e[i].second == 1)
      cout << e[i].first.first + 1 << " " << e[i].first.second + 1 << " "
           << 1 - e[i].second << '\n';
  }
  return 0;
}
