#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > E[111111];
int D[111111][2];
int B[111111];
int P[111111];
int nxt[111111];
int N, M;
struct Edge {
  int u, v, c;
  Edge(int u, int v, int c) : u(u), v(v), c(c) {}
  bool operator<(Edge b) const {
    if (b.u == u) return v < b.v;
    return u < b.u;
  }
  void print() { printf("%d %d %d\n", u, v, c); }
};
bool comp(Edge a, Edge b) {
  if (b.u == a.u) return a.v < b.v;
  return a.u < b.u;
}
vector<Edge> answer;
void bfs(int start, int id) {
  queue<int> Q;
  Q.push(start);
  for (int i = 1; i <= N; i++) D[i][id] = 111111;
  D[start][id] = 0;
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    for (int i = 0; i < E[x].size(); i++) {
      int u = E[x][i].first;
      if (D[u][id] > D[x][id] + 1) {
        D[u][id] = D[x][id] + 1;
        Q.push(u);
      }
    }
  }
}
bool equal(Edge a, Edge b) { return a.u == b.u and a.v == b.v; }
int main() {
  cin >> N >> M;
  int u, v, c;
  int current = 0;
  while (M--) {
    scanf("%d %d %d", &u, &v, &c);
    E[u].push_back({v, c});
    E[v].push_back({u, c});
    if (c == 1) current++;
  }
  bfs(1, 0);
  bfs(N, 1);
  queue<int> Q;
  Q.push(1);
  B[1] = 0;
  P[0] = P[1] = -1;
  while (!Q.empty()) {
    v = Q.front();
    Q.pop();
    for (int i = 0; i < E[v].size(); i++) {
      int u = E[v][i].first, c = E[v][i].second;
      if (D[u][0] == D[v][0] + 1 and D[u][0] + D[u][1] == D[1][1]) {
        B[u] = max(B[u], B[v] + c);
        if (B[u] == B[v] + c) {
          P[u] = v;
          Q.push(u);
        }
      }
    }
  }
  v = N;
  while (P[v] != -1) {
    nxt[P[v]] = v;
    v = P[v];
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < E[i].size(); j++) {
      u = min(i, E[i][j].first), v = max(i, E[i][j].first);
      if (nxt[u] != v and nxt[v] != u) {
        if (E[i][j].second == 1) answer.push_back(Edge(u, v, 0));
      } else if (E[i][j].second == 0)
        answer.push_back(Edge(u, v, 1));
    }
  }
  sort(answer.begin(), answer.end());
  cout << answer.size() / 2 << endl;
  for (int i = 0; i < answer.size(); i++) {
    if (i == 0 or !equal(answer[i], answer[i - 1])) answer[i].print();
  }
}
