#include <bits/stdc++.h>
using namespace std;
const int oo = 1000000009;
const double eps = 1e-9;
const int mod = 1000000007;
int parents[100001], child[100001], cnt[100001], dst[100001];
bool visited[100001];
vector<pair<int, int> > edge[100001];
void bfs() {
  int temp, ver, pos;
  queue<int> mq;
  mq.push(1);
  for (int i = 2; i < 100001 + 1; ++i) cnt[i] = 1e9;
  visited[1] = true;
  while (!mq.empty()) {
    temp = mq.front();
    mq.pop();
    for (int i = 0; i < edge[temp].size(); ++i) {
      ver = edge[temp][i].first;
      pos = edge[temp][i].second;
      if (!visited[ver]) {
        dst[ver] = 1 + dst[temp];
        cnt[ver] = (1 - pos) + cnt[temp];
        mq.push(ver);
        visited[ver] = true;
      }
      if (dst[ver] >= 1 + dst[temp] && cnt[ver] >= cnt[temp] + !pos) {
        cnt[ver] = cnt[temp] + !pos;
        parents[ver] = temp;
      }
    }
  }
}
int main() {
  int n, m, a, b, c, z, o;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", &a, &b, &c);
    edge[a].push_back(make_pair(b, c));
    edge[b].push_back(make_pair(a, c));
    if (c)
      ++o;
    else
      ++z;
  }
  bfs();
  int papa = n, ver, pos;
  cout << (o + 2 * cnt[papa] - dst[papa]) << "\n";
  while (parents[papa] != 0) {
    child[parents[papa]] = papa;
    papa = parents[papa];
  }
  for (int i = 1; i < n + 1; ++i) {
    for (int j = 0; j < edge[i].size(); ++j) {
      ver = edge[i][j].first;
      pos = edge[i][j].second;
      if (ver > i) {
        if ((child[i] == ver || child[ver] == i) && pos == 0)
          printf("%d %d 1\n", i, ver);
        else if (child[i] != ver && child[ver] != i && pos == 1)
          printf("%d %d 0\n", i, ver);
      }
    }
  }
}
