#include <bits/stdc++.h>
using namespace std;
class Road {
 public:
  int x, y, z;
  Road(int xx = 0, int yy = 0, int zz = 0) : x(xx), y(yy), z(zz) {}
};
class Path {
 public:
  int next, index;
  Path(int n = 0, int i = 0) : next(n), index(i) {}
};
class Node {
 public:
  int loc, step, good, parent, edge;
  Node(int l = 0, int s = 0, int g = 0, int p = 0, int e = 0)
      : loc(l), step(s), good(g), parent(p), edge(e) {}
  bool operator<(const Node& a) const {
    if (step != a.step) {
      return step > a.step;
    }
    return good < a.good;
  }
};
int n, m;
class Parent {
 public:
  Parent(int p = 0, int e = 0) : parent(p), edge(e) {}
  int parent, edge;
};
vector<vector<Path>> edge;
vector<Parent> parent;
vector<Road> edges;
bitset<100001> vis;
pair<int, int> dij() {
  Node temp(1, 0, 0, -1, -1);
  priority_queue<Node> q;
  q.push(temp);
  vis.reset();
  while (!q.empty()) {
    temp = q.top();
    q.pop();
    if (vis[temp.loc]) continue;
    vis.set(temp.loc);
    parent[temp.loc] = Parent(temp.parent, temp.edge);
    if (temp.loc == n) break;
    for (auto x : edge[temp.loc]) {
      if (vis[x.next]) continue;
      Node temp2;
      temp2.step = temp.step + 1;
      temp2.good = temp.good;
      temp2.loc = x.next;
      temp2.parent = temp.loc;
      temp2.edge = x.index;
      if (edges[temp2.edge].z) {
        temp2.good++;
      }
      q.push(temp2);
    }
  }
  pair<int, int> ans = {0, 0};
  int loc = n;
  while (loc != 1) {
    if (edges[parent[loc].edge].z == 1) {
      edges[parent[loc].edge].z = 3;
      ans.first++;
    } else {
      ans.second++;
      edges[parent[loc].edge].z = 2;
    }
    loc = parent[loc].parent;
  }
  return ans;
}
int main() {
  cin >> n >> m;
  edge = vector<vector<Path>>(n + 1, vector<Path>());
  parent = vector<Parent>(n + 1, Parent());
  int good = 0, bad = 0;
  for (int i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    if (z == 1)
      good++;
    else
      bad++;
    edges.emplace_back(x, y, z);
    edge[x].emplace_back(y, i);
    edge[y].emplace_back(x, i);
  }
  auto ans = dij();
  cout << ans.second + good - ans.first << endl;
  for (auto x : edges) {
    if (x.z != 3 && x.z != 0) {
      cout << x.x << " " << x.y << " " << (1 - x.z % 2) << endl;
    }
  }
}
