#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m, cnt = 0, numV[2];
struct Edge {
  int from, to, z;
};
struct View {
  int num[2], dis, e;
  bool bvisited;
  View() {
    num[0] = num[1] = 0;
    bvisited = false;
  }
};
Edge e[N << 1];
View v[N];
vector<int> root[N];
vector<pair<int, int> > ans;
void addEdge(int x, int y, int z) {
  e[cnt].from = x;
  e[cnt].to = y;
  e[cnt].z = z;
  root[x].push_back(cnt++);
}
int main() {
  cin >> n >> m;
  numV[0] = numV[1] = 0;
  for (int i = 0, x, y, z; i < m; i++) {
    cin >> x >> y >> z;
    numV[z]++;
    addEdge(x, y, z);
    addEdge(y, x, z);
  }
  queue<int> q;
  q.push(1);
  v[1].dis = 1;
  v[1].bvisited = true;
  while (1) {
    int index = q.front();
    q.pop();
    for (int i = 0, x; i < root[index].size(); i++) {
      x = e[root[index][i]].to;
      if (x == n) {
        v[index].num[e[root[index][i]].z]++;
        ans.push_back(make_pair(index, root[index][i]));
        break;
      }
      if (!v[x].bvisited) {
        v[x].dis = v[index].dis + 1;
        v[x].num[0] = v[index].num[0];
        v[x].num[1] = v[index].num[1];
        v[x].bvisited = true;
        v[x].e = root[index][i];
        v[x].num[e[root[index][i]].z]++;
        q.push(x);
      } else if (v[x].dis == v[index].dis + 1 &&
                 v[x].num[0] > v[index].num[0] + !e[root[index][i]].z) {
        v[x].num[0] = v[index].num[0];
        v[x].num[1] = v[index].num[1];
        v[x].e = root[index][i];
        v[x].num[e[root[index][i]].z]++;
      }
    }
    if (ans.size() > 0 && (q.size() == 0 || v[index].dis != v[q.front()].dis))
      break;
  }
  int tmin = N, index = -1;
  for (int i = 0; i < ans.size(); i++) {
    if (tmin > v[ans[i].first].num[0] + numV[1] - v[ans[i].first].num[1]) {
      tmin = v[ans[i].first].num[0] + numV[1] - v[ans[i].first].num[1];
      index = ans[i].second;
    }
  }
  cout << tmin << endl;
  while (1) {
    if (e[index].z)
      e[index | 1].z = 0;
    else
      cout << e[index | 1].to << " " << e[index | 1].from << " " << 1 << endl;
    if (e[index].from == 1) break;
    index = v[e[index].from].e;
  }
  for (int i = 0; i < m; i++)
    if (e[(i << 1) | 1].z)
      cout << e[(i << 1) | 1].to << " " << e[(i << 1) | 1].from << " " << 0
           << endl;
  return 0;
}
