#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
const long long INF = 1e18;
const long double EPS = 1e-12;
const int inf = 2e9;
vector<vector<pair<int, int>>> adj;
int vi[100005];
int dist[100005];
int pa[100005];
queue<int> qu;
vector<pair<int, int>> vec;
int ma[100005] = {0};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  int one = 0;
  adj.resize(n + 5);
  for (int i = (int)1; i < (int)m + 1; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    one += z;
    adj[x].push_back(make_pair(y, z));
    adj[y].push_back(make_pair(x, z));
  }
  for (int i = (int)1; i < (int)n + 1; i++) vi[i] = 0;
  vi[1] = 1;
  dist[1] = 0;
  qu.push(1);
  while (!qu.empty()) {
    int u = qu.front();
    qu.pop();
    int v, w;
    for (int i = 0; i < (int)adj[u].size(); i++) {
      v = adj[u][i].first;
      w = adj[u][i].second;
      if (vi[v] == 0) {
        vi[v] = 1;
        pa[v] = u;
        dist[v] = dist[u] + 1;
        qu.push(v);
      }
    }
  }
  for (int i = (int)1; i < (int)n + 1; i++) {
    vec.push_back(make_pair(dist[i], i));
  }
  sort(vec.begin(), vec.end());
  ma[1] = 0;
  for (int i = 0; i < (int)vec.size(); i++) {
    int di = vec[i].first + 1;
    int u = vec[i].second;
    int v, w;
    for (int i = 0; i < (int)adj[u].size(); i++) {
      v = adj[u][i].first;
      w = adj[u][i].second;
      if (dist[v] == di) {
        if (ma[v] < ma[u] + w) {
          ma[v] = ma[u] + w;
          pa[v] = u;
        }
      }
    }
  }
  int ans = dist[n] + one - 2 * ma[n];
  cout << ans << endl;
  for (int i = (int)1; i < (int)n + 1; i++) {
    vi[i] = 0;
  }
  vi[1] = vi[n] = 1;
  int x = n;
  while (x != 1) {
    vi[x] = 1;
    x = pa[x];
  }
  for (int i = (int)1; i < (int)n + 1; i++) {
    for (int j = 0; j < (int)adj[i].size(); j++) {
      int v = adj[i][j].first;
      int z = adj[i][j].second;
      if (i > v) continue;
      if (vi[i] == 1 && vi[v] == 1) {
        if (z == 0) {
          cout << i << " " << v << " 1" << endl;
        }
      } else {
        if (z == 1) {
          cout << i << " " << v << " 0" << endl;
        }
      }
    }
  }
  return 0;
}
