#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > g[100005];
int dist[100005], dp[100005], pr[100005];
vector<pair<int, int> > v;
set<pair<int, int> > f;
vector<string> ans;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    x--, y--;
    g[x].push_back(make_pair(y, z));
    g[y].push_back(make_pair(x, z));
  }
  for (int i = 0; i < n; i++) dist[i] = dp[i] = 1e9 + 7;
  priority_queue<pair<int, int> > q;
  dist[0] = 0;
  q.push(make_pair(0, 0));
  while (q.size()) {
    pair<int, int> top = q.top();
    q.pop();
    if (dist[top.second] != -top.first) continue;
    for (int p = 0; p < g[top.second].size(); p++) {
      if (dist[g[top.second][p].first] > -top.first + 1) {
        dist[g[top.second][p].first] = -top.first + 1;
        q.push(
            make_pair(-dist[g[top.second][p].first], g[top.second][p].first));
      }
    }
  }
  for (int i = 0; i < n; i++) v.push_back(make_pair(dist[i], i));
  sort(v.begin(), v.end());
  memset(pr, -1, sizeof(pr));
  dp[0] = 0;
  for (int u = 0; u < v.size(); u++) {
    for (int p = 0; p < g[v[u].second].size(); p++) {
      if (dist[v[u].second] + 1 != dist[g[v[u].second][p].first]) continue;
      if (dp[g[v[u].second][p].first] >
          dp[v[u].second] + 1 - g[v[u].second][p].second) {
        dp[g[v[u].second][p].first] =
            dp[v[u].second] + 1 - g[v[u].second][p].second;
        pr[g[v[u].second][p].first] =
            v[u].second * 2 + g[v[u].second][p].second;
      }
    }
  }
  int cur = n - 1;
  while (cur != 0) {
    int ur = pr[cur] / 2;
    if (pr[cur] % 2 == 0) {
      ostringstream ss;
      ss << ur + 1 << " " << cur + 1 << " " << 1;
      ans.push_back(ss.str());
    }
    f.insert(make_pair(ur, cur));
    f.insert(make_pair(cur, ur));
    cur = ur;
  }
  for (int i = 0; i < n; i++) {
    for (int p = 0; p < g[i].size(); p++) {
      if (g[i][p].second && !f.count(make_pair(i, g[i][p].first))) {
        ostringstream ss;
        ss << i + 1 << " " << g[i][p].first + 1 << " " << 0;
        ans.push_back(ss.str());
        f.insert(make_pair(g[i][p].first, i));
        f.insert(make_pair(i, g[i][p].first));
      }
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) cout << ans[i].c_str() << endl;
  return 0;
}
