#include <bits/stdc++.h>
using namespace std;
int dist[100005], visited[100005], dp[100005], cnt = 0;
vector<int> graph[100005], state[100005];
void dfs(int v) {
  visited[v] = 2;
  cnt++;
  int temp = 100005;
  for (int i = 0; i < graph[v].size(); i++) {
    int u = graph[v][i];
    if (dist[u] == dist[v] - 1) temp = min(temp, dp[u]);
  }
  for (int i = 0, j = 0; i < graph[v].size() && j < state[v].size(); i++, j++) {
    int u = graph[v][i], z = state[v][j];
    if (visited[u] == 1) {
      if ((dist[u] == dist[v] - 1) && dp[u] == temp) {
        if (z == 0) {
          if (dp[u] < dp[v]) {
            dfs(u);
            break;
          }
        } else {
          if (dp[u] == dp[v]) {
            dfs(u);
            break;
          }
        }
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m, u, v, z;
  cin >> n >> m;
  int a[m], b[m], c[m], a1[m], b1[m], c1[m];
  for (int i = 0; i < m; i++) {
    cin >> u >> v >> z;
    a[i] = u, b[i] = v, c[i] = z;
    graph[u].push_back(v);
    graph[v].push_back(u);
    state[u].push_back(z);
    state[v].push_back(z);
  }
  int s = 1;
  list<int> queue;
  visited[1] = 1;
  queue.push_back(s);
  while (!queue.empty()) {
    s = queue.front();
    queue.pop_front();
    for (int i = 0, j = 0; i < graph[s].size() && j < state[s].size();
         i++, j++) {
      u = graph[s][i], v = state[s][j];
      if (visited[u] == 0) {
        visited[u] = 1;
        dp[u] = dp[s] + (1 - v);
        dist[u] = dist[s] + 1;
        queue.push_back(u);
      } else {
        if (dist[u] == dist[s] + 1) {
          dp[u] = min(dp[u], dp[s] + (1 - v));
        }
      }
    }
  }
  dfs(n);
  int j = 0;
  for (int i = 0; i < m; i++) {
    u = a[i], v = b[i], z = c[i];
    if (visited[u] == 2 && visited[v] == 2) {
      if (z == 0) {
        a1[j] = u, b1[j] = v, c1[j] = 1;
        j++;
      }
    } else {
      if (z == 1) {
        a1[j] = u, b1[j] = v, c1[j] = 0;
        j++;
      }
    }
  }
  cout << j << "\n";
  for (int i = 0; i < j; i++) {
    cout << a1[i] << " " << b1[i] << " " << c1[i] << "\n";
  }
  return 0;
}
