#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long double EPS = 1e-8;
vector<vector<pair<int, int>>> g;
vector<pair<int, int>> par;
vector<int> dp, dp1;
struct Road {
  int a, b, s;
  void getVal(int a, int b, int s) {
    this->a = a;
    this->b = b;
    this->s = s;
  }
  void print() { cout << a << " " << b << " " << s; }
};
vector<Road> roads;
struct CR {
  int d, r;
  bool operator<(const CR &cr) const {
    return (d < cr.d || d == cr.d && cr.r < r);
  }
};
CR mcr(int d, int r) {
  CR cr;
  cr.d = d;
  cr.r = r;
  return cr;
}
int main() {
  int n, m;
  cin >> n >> m;
  g.resize(n);
  roads.resize(m);
  dp.assign(n, INF);
  dp1.assign(n, 0);
  par.assign(n, make_pair(-1, -1));
  for (int i = 0; i < m; i++) {
    int a, b, s;
    cin >> a >> b >> s;
    roads[i].getVal(a, b, s);
    a--;
    b--;
    g[a].push_back(make_pair(b, i));
    g[b].push_back(make_pair(a, i));
  }
  set<pair<CR, int>> q;
  dp[0] = 0;
  dp1[0] = 0;
  q.insert(make_pair(mcr(dp[0], 0), 0));
  while (!q.empty()) {
    int v = q.begin()->second;
    q.erase(q.begin());
    if (v == n - 1) break;
    for (int i = 0; i < g[v].size(); i++) {
      int to = g[v][i].first;
      int cut = roads[g[v][i].second].s;
      if (dp[to] > dp[v] + 1 || dp[to] == dp[v] + 1 && dp1[to] < dp1[v] + cut) {
        q.erase(make_pair(mcr(dp[to], dp1[to]), to));
        dp[to] = dp[v] + 1;
        dp1[to] = dp1[v] + cut;
        par[to] = make_pair(v, g[v][i].second);
        q.insert(make_pair(mcr(dp[to], dp1[to]), to));
      }
    }
  }
  vector<int> answer;
  vector<char> taken(m, false);
  int v = n - 1;
  while (par[v].first != -1) {
    if (roads[par[v].second].s == 0) {
      answer.push_back(par[v].second);
      roads[par[v].second].s ^= 1;
    }
    taken[par[v].second] = true;
    v = par[v].first;
  }
  for (int i = 0; i < m; i++) {
    if (!taken[i] && roads[i].s == 1) {
      answer.push_back(i);
      roads[i].s = 0;
    }
  }
  cout << answer.size() << endl;
  for (int i = 0; i < answer.size(); i++) {
    roads[answer[i]].print();
    cout << endl;
  }
  return 0;
}
