#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
vector<pair<int, int> > G[N];
int n, m, u[N], v[N], z[N];
int dist[N];
queue<pair<int, int> > q;
bool used[N];
int dp[N];
int parent[N];
int t[N];
void bfs(int v) {
  dist[v] = 0;
  q.push(make_pair(v, 0));
  used[v] = true;
  while (q.empty() == false) {
    pair<int, int> cur = q.front();
    q.pop();
    for (int i = 0; i < G[cur.first].size(); ++i) {
      if (used[G[cur.first][i].first] == false) {
        used[G[cur.first][i].first] = true;
        q.push(make_pair(G[cur.first][i].first, cur.second + 1));
        dist[G[cur.first][i].first] = cur.second + 1;
      }
    }
  }
}
int solve(int v) {
  if (v == 1) return 0;
  if (dp[v] != -1) return dp[v];
  dp[v] = (int)1e9;
  for (int i = 0; i < G[v].size(); ++i) {
    if (dist[v] == dist[G[v][i].first] + 1) {
      int tmp = solve(G[v][i].first);
      if (dp[v] > tmp + 1 - G[v][i].second) {
        dp[v] = tmp + 1 - G[v][i].second;
        parent[v] = G[v][i].first;
      }
    }
  }
  return dp[v];
}
int main() {
  scanf("%d%d", &n, &m);
  int cnt = 0;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", &u[i], &v[i], &z[i]);
    G[u[i]].push_back(make_pair(v[i], z[i]));
    G[v[i]].push_back(make_pair(u[i], z[i]));
    if (z[i] == 1) cnt++;
  }
  bfs(1);
  memset(dp, -1, sizeof(dp));
  memset(t, -1, sizeof(t));
  dp[n] = solve(n);
  int vertex = n;
  while (vertex != 1) {
    t[vertex] = parent[vertex];
    vertex = parent[vertex];
  }
  printf("%d\n", dp[n] + cnt - dist[n] + dp[n]);
  for (int i = 0; i < m; ++i) {
    if (t[u[i]] == v[i] || t[v[i]] == u[i]) {
      if (z[i] == 0) printf("%d %d %d\n", u[i], v[i], 1);
    } else {
      if (z[i] == 1) printf("%d %d %d\n", u[i], v[i], 0);
    }
  }
  return 0;
}
