#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<pair<int, int> > E[111111];
bool solved[111111];
int prevN[111111];
int total = 0;
void solve();
int main() {
  cin >> N >> M;
  memset(solved, 0, sizeof(solved));
  memset(prevN, -1, sizeof(prevN));
  for (int i = 0; i < M; ++i) {
    int t1, t2, t3;
    cin >> t1 >> t2 >> t3;
    t3 = 1 - t3;
    E[t1].push_back(make_pair(t2, t3));
    E[t2].push_back(make_pair(t1, t3));
  }
  solve();
}
void solve() {
  priority_queue<pair<pair<int, int>, pair<int, int> > > p;
  p.push(make_pair(make_pair(0, 0), make_pair(1, -1)));
  while (!p.empty()) {
    int length = p.top().first.first;
    int cost = p.top().first.second;
    int curr = p.top().second.first;
    int prev = p.top().second.second;
    p.pop();
    if (solved[curr]) {
      continue;
    }
    if (curr == N) {
      prevN[curr] = prev;
      break;
    }
    prevN[curr] = prev;
    solved[curr] = 1;
    for (int i = 0; i < E[curr].size(); ++i) {
      int next = E[curr][i].first;
      int step = E[curr][i].second;
      if (solved[next]) {
        continue;
      }
      p.push(
          make_pair(make_pair(length - 1, cost - step), make_pair(next, curr)));
    }
  }
  set<pair<int, int> > S;
  set<pair<int, int> > finished;
  int curr = N;
  while (prevN[curr] != -1) {
    int prev = prevN[curr];
    S.insert(make_pair(prev, curr));
    S.insert(make_pair(curr, prev));
    curr = prev;
  }
  vector<pair<int, pair<int, int> > > out;
  for (int i = 1; i <= N; ++i) {
    for (int j = 0; j < E[i].size(); ++j) {
      int b = E[i][j].first;
      int a = i;
      int cost = 1 - E[i][j].second;
      if (finished.find(make_pair(a, b)) != finished.end() ||
          finished.find(make_pair(b, a)) != finished.end()) {
        continue;
      }
      if (S.find(make_pair(a, b)) != S.end()) {
        if (cost == 0) {
          out.push_back(make_pair(a, make_pair(b, 1)));
          total++;
        }
      } else {
        if (cost == 1) {
          out.push_back(make_pair(a, make_pair(b, 0)));
          total++;
        }
      }
      finished.insert(make_pair(a, b));
      finished.insert(make_pair(b, a));
    }
  }
  cout << total << endl;
  for (int i = 0; i < out.size(); ++i) {
    cout << out[i].first << " " << out[i].second.first << " "
         << out[i].second.second << endl;
  }
}
