#include <bits/stdc++.h>
using namespace std;
const int N = 100007;
const int INF = (1e9) + 7;
struct edge {
  int to, f;
  edge() {}
  edge(int a, int b) {
    to = a;
    f = b;
  }
};
struct el {
  int vertex;
  pair<int, int> cost;
  el() {}
  el(int a, pair<int, int> b) {
    vertex = a;
    cost = b;
  }
  bool operator<(const el &a) const { return cost > a.cost; }
};
int n, m, r, s;
vector<edge> v[N];
pair<int, int> dist[N];
int from[N];
priority_queue<el> q;
set<pair<int, int> > path;
vector<pair<int, int> > broken, regular;
void dijkstra() {
  int i;
  el curr;
  for (i = 1; i <= n; i++) {
    dist[i] = make_pair(INF, INF);
  }
  dist[1] = make_pair(0, 0);
  q.push(el(1, dist[1]));
  while (!q.empty()) {
    curr = q.top();
    q.pop();
    for (i = 0; i < (int)(v[curr.vertex].size()); i++) {
      pair<int, int> current_distance = curr.cost;
      ++current_distance.first;
      if (v[curr.vertex][i].f == 0) ++current_distance.second;
      if (current_distance < dist[v[curr.vertex][i].to]) {
        dist[v[curr.vertex][i].to] = current_distance;
        from[v[curr.vertex][i].to] = curr.vertex;
        q.push(el(v[curr.vertex][i].to, current_distance));
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, x, y, z, where, prev;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d %d %d", &x, &y, &z);
    if (x > y) swap(x, y);
    v[x].push_back(edge(y, z));
    v[y].push_back(edge(x, z));
    if (z == 0) {
      broken.push_back(make_pair(x, y));
      ++r;
    } else {
      regular.push_back(make_pair(x, y));
    }
  }
  dijkstra();
  s = dist[n].first;
  x = dist[n].second;
  printf("%d\n", m - s - r + 2 * x);
  where = n;
  while ((prev = from[where]) > 0) {
    path.insert(make_pair(min(prev, where), max(prev, where)));
    where = prev;
  }
  for (i = 0; i < (int)(broken.size()); i++)
    if (path.find(broken[i]) != path.end())
      printf("%d %d 1\n", broken[i].first, broken[i].second);
  for (i = 0; i < (int)(regular.size()); i++)
    if (path.find(regular[i]) == path.end())
      printf("%d %d 0\n", regular[i].first, regular[i].second);
  return 0;
}
