#include <bits/stdc++.h>
using namespace std;
bool debug = 1;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long ln, lk, lm;
struct eg {
  int u, v, z;
} e[100025];
vector<pair<int, int>> mp[100025];
bool used[100025];
pair<int, int> dp[100025];
pair<int, int> pre[100025];
bool inp[100025];
void dij() {
  priority_queue<pair<pair<int, int>, int>,
                 std::vector<pair<pair<int, int>, int>>,
                 std::greater<pair<pair<int, int>, int>>>
      q;
  q.push({{0, 0}, 1});
  for (int(i) = 1; (i) <= (int)(n); (i)++) dp[i] = {(1 << 30), (1 << 30)};
  dp[1] = {0, 0};
  while (!q.empty()) {
    int x = q.top().second;
    int dis = q.top().first.first, bad = q.top().first.second;
    q.pop();
    if (used[x]) continue;
    used[x] = 1;
    for (auto p : mp[x]) {
      int y = p.first, id = p.second;
      auto key = make_pair(dis + 1, bad + (e[id].z == 0));
      if (key < dp[y]) {
        assert(used[y] == false);
        dp[y] = key;
        q.push({key, y});
        pre[y] = {x, id};
      }
    }
  }
  for (int tar = n; tar != 1;) {
    auto p = pre[tar];
    inp[p.second] = 1;
    tar = p.first;
  }
  vector<int> ans;
  for (int(i) = 0; (i) < (int)(m); (i)++) {
    if (inp[i] && e[i].z == 0)
      ans.push_back(i);
    else if (!inp[i] && e[i].z == 1)
      ans.push_back(i);
  }
  printf("%d\n", ans.size());
  for (int c : ans) {
    printf("%d %d %d\n", e[c].u, e[c].v, 1 - e[c].z);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0, u, v, z; i < m; i++) {
    scanf("%d%d%d", &u, &v, &z);
    mp[u].push_back({v, i});
    mp[v].push_back({u, i});
    e[i].u = u;
    e[i].v = v;
    e[i].z = z;
  }
  dij();
  return 0;
}
