#include <bits/stdc++.h>
#pragma optimize("-O3")
using namespace std;
const long long mod = 998244353;
int n, m;
int x[100005], y[100005], z[100005];
vector<pair<int, int> > adj[100005];
bool vis[100005];
int dis[100005], mn[100005], p[100005];
vector<int> nodeat[100005];
void swap(int &i, int &j) {
  if (i < j) return;
  int tmp = i;
  i = j;
  j = tmp;
}
void solve() {
  cin >> n >> m;
  int k = 0;
  fill(mn, mn + n, (int)1e7);
  for (long long i = (long long)0; i != (long long)m; i = i + 1) {
    cin >> x[i] >> y[i] >> z[i];
    k += z[i] ^ 1;
    x[i]--;
    y[i]--;
    adj[x[i]].push_back(make_pair(y[i], z[i]));
    adj[y[i]].push_back(make_pair(x[i], z[i]));
  }
  queue<int> q;
  q.push(0);
  nodeat[0].push_back(0);
  vis[0] = 1;
  mn[0] = 0;
  p[0] = -1;
  while (!q.empty()) {
    int i = q.front();
    q.pop();
    for (auto &x : adj[i]) {
      if (vis[x.first]) {
        if (dis[x.first] == dis[i] + 1) {
          if (mn[x.first] > mn[i] + (x.second ^ 1)) {
            mn[x.first] = mn[i] + (x.second ^ 1);
            p[x.first] = i;
          }
        }
        continue;
      }
      vis[x.first] = 1;
      dis[x.first] = dis[i] + 1;
      ;
      mn[x.first] = mn[i] + (x.second ^ 1);
      ;
      p[x.first] = i;
      q.push(x.first);
    }
  };
  int ans = m - dis[n - 1] - k + 2 * mn[n - 1];
  ;
  set<pair<int, int> > path;
  int cr = n - 1;
  while (p[cr] != -1) {
    int i = cr, j = p[cr];
    swap(i, j);
    path.insert(make_pair(i, j));
    cr = p[cr];
  }
  cout << ans << '\n';
  for (long long i = (long long)0; i != (long long)m; i = i + 1) {
    int a = x[i], b = y[i];
    swap(a, b);
    auto it = path.find(make_pair(a, b));
    if (it == path.end()) {
      if (z[i] == 1) {
        cout << x[i] + 1 << " " << y[i] + 1 << " " << 0 << '\n';
      }
    } else {
      if (z[i] == 0) {
        cout << x[i] + 1 << " " << y[i] + 1 << " " << 1 << '\n';
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
}
