#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<long long, long long>, long long> > edges;
vector<pair<long long, long long> > g[200005];
queue<long long> q;
long long initial;
map<pair<long long, long long>, long long> mp;
struct node {
  long long dist;
  long long parent;
  long long repairs;
  long long total;
  long long ans;
};
node dp[200005];
bool vis[200005];
int main() {
  std::ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i <= m - 1; i++) {
    long long x, y, z;
    cin >> x >> y >> z;
    g[x].push_back(make_pair(y, z));
    g[y].push_back(make_pair(x, z));
    edges.push_back(make_pair(make_pair(x, y), z));
    if (z == 0) initial++;
    mp[make_pair(x, y)] = i;
    mp[make_pair(y, x)] = i;
  }
  for (long long i = 0; i <= n + 5; i++) dp[i].dist = 1000000009;
  dp[1].dist = dp[1].repairs = dp[1].total = dp[1].ans = 0ll;
  dp[1].parent = -1ll;
  q.push(1);
  while (!q.empty()) {
    long long nn = q.front();
    q.pop();
    long long sz = g[nn].size();
    for (long long i = 0; i <= sz - 1; i++) {
      long long child = g[nn][i].first;
      long long wt = g[nn][i].second;
      if (dp[child].dist == 1000000009) {
        dp[child].dist = dp[nn].dist + 1;
        if (wt == 0)
          dp[child].repairs = dp[nn].repairs + 1;
        else
          dp[child].repairs = dp[nn].repairs;
        dp[child].total = dp[nn].total + 1;
        dp[child].parent = nn;
        dp[child].ans = m - dp[child].total + 2 * dp[child].repairs - initial;
        q.push(child);
      } else if (dp[child].dist == dp[nn].dist + 1) {
        long long newans;
        if (wt == 0)
          newans = m - (dp[nn].total + 1) + 2 * (dp[nn].repairs + 1) - initial;
        else
          newans = m - (dp[nn].total + 1) + 2 * (dp[nn].repairs) - initial;
        if (newans < dp[child].ans) {
          if (wt == 0)
            dp[child].repairs = dp[nn].repairs + 1;
          else
            dp[child].repairs = dp[nn].repairs;
          dp[child].total = dp[nn].total + 1;
          dp[child].parent = nn;
          dp[child].ans = m - dp[child].total + 2 * dp[child].repairs - initial;
          q.push(child);
        }
      }
    }
  }
  long long num = dp[n].ans;
  cout << num << endl;
  long long nn = n;
  long long pp = dp[nn].parent;
  while (pp != -1) {
    long long id = mp[make_pair(nn, pp)];
    long long z = edges[id].second;
    vis[id] = 1;
    if (z == 0)
      cout << edges[id].first.first << " " << edges[id].first.second << " "
           << !z << endl;
    nn = pp;
    pp = dp[nn].parent;
  }
  for (long long i = 0; i <= m - 1; i++) {
    if (vis[i]) continue;
    if (edges[i].second == 1)
      cout << edges[i].first.first << " " << edges[i].first.second << " "
           << !(edges[i].second) << endl;
  }
  return 0;
}
