#include <bits/stdc++.h>
using namespace std;
struct edge {
  int v2;
  bool work;
  edge(int v, bool flag) {
    v2 = v;
    work = flag;
  }
};
vector<edge> adj[100005];
vector<pair<int, int> > dp(100005, make_pair(100000000, 1000000000)), ans1,
    ans2;
vector<bool> visited(100005, false);
vector<int> p(100005, -1);
map<pair<int, int>, bool> inpath, check;
void bfs(int s) {
  list<int> q;
  q.push_back(s);
  while (!q.empty()) {
    visited[q.front()] = true;
    s = q.front();
    q.pop_front();
    vector<edge>::iterator itv;
    for (itv = adj[s].begin(); itv != adj[s].end(); itv++) {
      if (dp[itv->v2].first > dp[s].first + 1) {
        dp[itv->v2].first = dp[s].first + 1;
        if (!(itv->work))
          dp[itv->v2].second = dp[s].second + 1;
        else
          dp[itv->v2].second = dp[s].second;
        p[itv->v2] = s;
      } else if (dp[itv->v2].first == dp[s].first + 1) {
        if (itv->work && dp[itv->v2].second > dp[s].second) {
          dp[itv->v2].second = dp[s].second;
          p[itv->v2] = s;
        } else if (!(itv->work) && dp[itv->v2].second > dp[s].second + 1) {
          dp[itv->v2].second = dp[s].second + 1;
          p[itv->v2] = s;
        }
      }
      if (!visited[itv->v2]) {
        q.push_back(itv->v2);
        visited[itv->v2] = true;
      }
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  int i;
  for (i = 0; i < m; i++) {
    int x, y;
    bool z;
    cin >> x >> y >> z;
    adj[x - 1].push_back(edge(y - 1, z));
    adj[y - 1].push_back(edge(x - 1, z));
  }
  dp[0].first = dp[0].second = 0;
  bfs(0);
  i = n - 1;
  while (p[i] != -1) {
    inpath[make_pair(i, p[i])] = true;
    inpath[make_pair(p[i], i)] = true;
    i = p[i];
  }
  for (i = 0; i < n; i++) {
    vector<edge>::iterator itv;
    for (itv = adj[i].begin(); itv != adj[i].end(); itv++) {
      if (!inpath[make_pair(i, itv->v2)] && !check[make_pair(i, itv->v2)] &&
          itv->work) {
        ans1.push_back(make_pair(i, itv->v2));
        check[make_pair(itv->v2, i)] = true;
      } else if (inpath[make_pair(i, itv->v2)] &&
                 !check[make_pair(i, itv->v2)] && !(itv->work)) {
        ans2.push_back(make_pair(i, itv->v2));
        check[make_pair(itv->v2, i)] = true;
      }
    }
  }
  cout << ans1.size() + ans2.size() << "\n";
  for (i = 0; i < ans1.size(); i++)
    cout << ans1[i].first + 1 << " " << ans1[i].second + 1 << " 0\n";
  for (i = 0; i < ans2.size(); i++)
    cout << ans2[i].first + 1 << " " << ans2[i].second + 1 << " 1\n";
}
