#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
struct Edge {
  int a, b, valid, id;
} A[MAX];
int N, M, V[MAX];
bool Check[MAX];
Edge p[MAX];
vector<Edge> adj[MAX];
int main() {
  scanf("%d%d", &N, &M);
  int num[2] = {};
  for (int i = 0; i < M; ++i) {
    scanf("%d%d%d", &A[i].a, &A[i].b, &A[i].valid);
    --A[i].a;
    --A[i].b;
    A[i].id = i;
    num[A[i].valid]++;
    adj[A[i].a].push_back(A[i]);
    adj[A[i].b].push_back(A[i]);
  }
  queue<int> q;
  memset(V, -1, sizeof(V));
  q.push(0);
  V[0] = 0;
  while (V[N - 1] == -1) {
    map<int, int> m;
    while (!q.empty()) {
      int cur = q.front();
      q.pop();
      for (auto &it : adj[cur]) {
        int next = cur ^ it.a ^ it.b;
        int cand = V[cur] + (it.valid ? 0 : 1);
        if (V[next] == -1) {
          if (m.find(next) == m.end() || cand < m[next]) {
            m[next] = cand;
            p[next] = it;
          }
        }
      }
    }
    for (auto &it : m) {
      V[it.first] = it.second;
      q.push(it.first);
    }
  }
  int ans = 0;
  for (int cur = N - 1; cur != 0; cur = cur ^ p[cur].a ^ p[cur].b) {
    Check[p[cur].id] = true;
    if (!p[cur].valid)
      ++ans;
    else
      --num[1];
  }
  ans += num[1];
  printf("%d\n", ans);
  for (int i = 0; i < M; ++i) {
    if (Check[i] && !A[i].valid)
      printf("%d %d %d\n", A[i].a + 1, A[i].b + 1, 1);
    else if (!Check[i] && A[i].valid)
      printf("%d %d %d\n", A[i].a + 1, A[i].b + 1, 0);
  }
  return 0;
}
