#include <bits/stdc++.h>
using namespace std;
int n, m;
int first[100005];
int sum, ans, anr;
struct LIST {
  int u, v, z;
  bool flag;
  LIST(int u = 0, int v = 0, int z = 0) : u(u), v(v), z(z), flag(false){};
} List[100005];
struct EDGE {
  int u, v, next, id, z;
  EDGE(int u = 0, int v = 0, int n = 0, int i = 0, int z = 0)
      : u(u), v(v), next(n), id(i), z(z){};
} edge[100005 * 2];
int cnt;
struct node {
  int u, step, r;
  node(int u = 0, int s = 0, int r = 0) : u(u), step(s), r(r){};
  bool operator<(const node& b) const {
    return step > b.step || (step == b.step && r < b.r);
  }
} fa[100005];
void init() {
  cnt = 0;
  sum = ans = anr = 0;
  memset(first, 0, sizeof(first));
}
void addEdge(int u, int v, int id, int z) {
  edge[++cnt] = EDGE(u, v, first[u], id, z);
  first[u] = cnt;
  edge[++cnt] = EDGE(v, u, first[v], id, z);
  first[v] = cnt;
  List[id] = LIST(u, v, z);
}
void bfs() {
  priority_queue<node> Q;
  Q.push(node(1, 0, 0));
  while (!Q.empty()) {
    node u = Q.top();
    Q.pop();
    if (u.u == n) {
      ans = u.step;
      anr = u.r;
      break;
    }
    for (int i = first[u.u]; i != 0; i = edge[i].next) {
      EDGE v = edge[i];
      if (!fa[v.v].u || u.step + 1 == fa[v.v].step && u.r + v.z > fa[v.v].r) {
        fa[v.v] = node(i, u.step + 1, u.r + v.z);
        Q.push(node(v.v, u.step + 1, u.r + v.z));
      }
    }
  }
  int u = n;
  while (u != 1) {
    int i = fa[u].u;
    List[edge[i].id].flag = true;
    u = edge[i].u;
  }
}
int main() {
  init();
  cin >> n >> m;
  int u, v, z;
  for (int i = 1; i <= m; i++) {
    cin >> u >> v >> z;
    addEdge(u, v, i, z);
    if (z) sum++;
  }
  bfs();
  cout << sum + ans - 2 * anr << endl;
  for (int i = 1; i <= m; i++) {
    if (List[i].flag && List[i].z == 0 || !List[i].flag && List[i].z == 1)
      cout << List[i].u << " " << List[i].v << " " << (List[i].z + 1) % 2
           << endl;
  }
  return 0;
}
