#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, int>>> graph(n + 1), dag(n + 1);
  for (int i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    graph[x].push_back({y, z});
    graph[y].push_back({x, z});
  }
  vector<int> dists(n + 1, -1);
  queue<int> q;
  q.push(n);
  dists[n] = 0;
  while (q.size()) {
    int cur = q.front();
    q.pop();
    for (auto p : graph[cur]) {
      if (dists[p.first] == -1) {
        dists[p.first] = dists[cur] + 1;
        q.push(p.first);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (auto p : graph[i]) {
      if (dists[i] == dists[p.first] + 1) {
        dag[i].push_back({p.first, p.second});
      }
    }
  }
  vector<int> preds(n + 1, -1), dp(n + 1, MOD);
  dp[1] = 0;
  q.push(1);
  while (q.size()) {
    int cur = q.front();
    q.pop();
    for (auto p : dag[cur]) {
      if (preds[p.first] == -1) {
        q.push(p.first);
      }
      if (dp[cur] + !p.second < dp[p.first]) {
        preds[p.first] = cur;
        dp[p.first] = dp[cur] + !p.second;
      }
    }
  }
  set<pair<int, int>> used;
  int cur = n;
  while (cur != 1) {
    int x = preds[cur], y = cur;
    if (x > y) swap(x, y);
    used.insert({x, y});
    cur = preds[cur];
  }
  vector<pair<int, int>> ans;
  vector<int> ans2;
  for (int i = 1; i <= n; i++) {
    for (auto p : graph[i]) {
      if (i < p.first) {
        pair<int, int> p2 = {i, p.first};
        auto it = used.find(p2);
        if (it == used.end() && p.second) {
          ans.push_back(p2);
          ans2.push_back(0);
        } else if (it != used.end() && !p.second) {
          ans.push_back(p2);
          ans2.push_back(1);
        }
      }
    }
  }
  cout << ans.size() << '\n';
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i].first << ' ' << ans[i].second << ' ' << ans2[i] << '\n';
  }
  return 0;
}
