#include <bits/stdc++.h>
using namespace std;
bool yess[100004];
map<pair<pair<int, int>, int>, int> mp;
int n, m;
vector<pair<int, int> > g[100004];
bool vis[100004];
int dist1[100004], dist2[100004];
int x[100004], y[100004], z[100004];
bool okay(int a, int b, int co) {
  if (dist1[a] + 1 < dist1[b]) return true;
  if (dist1[a] + 1 == dist1[b] && dist2[a] + (1 - co) < dist2[b]) return true;
  return false;
}
bool okay2(int a, int b, int co) {
  if (dist1[a] == dist1[b] + 1 && dist2[a] == dist2[b] + (1 - co)) return true;
  return false;
}
vector<int> ans1, ans2, ans3;
void dfs(int xx) {
  if (xx == 1) return;
  for (int i = 0; i < g[xx].size(); i++)
    if (okay2(xx, g[xx][i].first, g[xx][i].second)) {
      yess[mp[make_pair(make_pair(xx, g[xx][i].first), g[xx][i].second)]] = 1;
      dfs(g[xx][i].first);
      break;
    }
}
int main() {
  cin >> n >> m;
  int num0 = 0;
  for (int i = 1; i <= n; i++) dist1[i] = dist2[i] = 1e9;
  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i] >> z[i];
    g[x[i]].push_back(make_pair(y[i], z[i]));
    g[y[i]].push_back(make_pair(x[i], z[i]));
    mp[make_pair(make_pair(x[i], y[i]), z[i])] = i;
    mp[make_pair(make_pair(y[i], x[i]), z[i])] = i;
    if (z[i] == 0) num0++;
  }
  priority_queue<pair<pair<int, int>, int>, vector<pair<pair<int, int>, int> >,
                 greater<pair<pair<int, int>, int> > >
      q;
  dist1[1] = 0;
  dist2[1] = 0;
  q.push(make_pair(make_pair(0, 0), 1));
  while (!q.empty()) {
    pair<pair<int, int>, int> pp = q.top();
    q.pop();
    if (vis[pp.second])
      continue;
    else
      vis[pp.second] = 1;
    int xx = pp.second;
    for (int i = 0; i < g[xx].size(); i++)
      if (okay(xx, g[xx][i].first, g[xx][i].second)) {
        dist1[g[xx][i].first] = dist1[xx] + 1;
        dist2[g[xx][i].first] = dist2[xx] + (1 - g[xx][i].second);
        q.push(
            make_pair(make_pair(dist1[g[xx][i].first], dist2[g[xx][i].first]),
                      g[xx][i].first));
      }
  }
  dfs(n);
  cout << dist2[n] + (m - num0) - (dist1[n] - dist2[n]) << endl;
  for (int i = 0; i < m; i++) {
    if (z[i] == 0 && yess[i]) cout << x[i] << " " << y[i] << " " << 1 << endl;
    if (z[i] == 1 && !yess[i]) cout << x[i] << " " << y[i] << " " << 0 << endl;
  }
  return 0;
}
