#include <bits/stdc++.h>
static constexpr int MAXN = 2e5 + 10;
struct edge {
  int src;
  int dest;
  int working;
  int index;
};
static int DP[MAXN];
static int dist[MAXN];
static std::vector<edge> graph[MAXN];
static bool edge_taken[MAXN];
static void bfs(int start) {
  std::queue<int> alexander;
  alexander.push(start);
  static bool visited[MAXN];
  visited[start] = true;
  dist[start] = 0;
  while (!alexander.empty()) {
    int next = alexander.front();
    alexander.pop();
    for (const edge& e : graph[next]) {
      if (!visited[e.dest]) {
        dist[e.dest] = dist[next] + 1;
        alexander.push(e.dest);
        visited[e.dest] = true;
      }
    }
  }
}
static int count(int node) {
  int& ref = DP[node];
  if (ref != -1) return ref;
  ref = 0;
  for (const edge& e : graph[node]) {
    if (dist[e.dest] == dist[node] - 1) {
      ref = std::max(ref, e.working + count(e.dest));
    }
  }
  return ref;
}
static void mark_path(int node) {
  for (const edge& e : graph[node]) {
    if (dist[e.dest] == dist[node] - 1 &&
        count(e.dest) == count(node) - e.working) {
      mark_path(e.dest);
      edge_taken[e.index] = true;
      break;
    }
  }
}
int main() {
  int nodes, edges;
  std::scanf("%d %d", &nodes, &edges);
  static edge get_edge[MAXN];
  for (int i = 0; i < edges; i++) {
    int src, dest, type;
    std::scanf("%d %d %d", &src, &dest, &type);
    src--, dest--;
    edge e = {src, dest, type, i};
    get_edge[i] = e;
    graph[src].push_back(e);
    std::swap(e.src, e.dest);
    graph[dest].push_back(e);
  }
  bfs(nodes - 1);
  std::fill(DP, DP + MAXN, -1);
  mark_path(0);
  int affected = edges;
  std::vector<int> not_taken;
  std::vector<int> broken;
  for (int i = 0; i < edges; i++) {
    edge e = get_edge[i];
    if ((edge_taken[i] && e.working) || (!edge_taken[i] && !e.working)) {
      affected--;
    } else if (edge_taken[i] && !e.working) {
      broken.push_back(i);
    } else if (!edge_taken[i] && e.working) {
      not_taken.push_back(i);
    }
  }
  std::cout << affected << std::endl;
  for (int gu : not_taken) {
    int src = get_edge[gu].src + 1;
    int dest = get_edge[gu].dest + 1;
    std::printf("%d %d 0\n", src, dest);
  }
  for (int gu : broken) {
    int src = get_edge[gu].src + 1;
    int dest = get_edge[gu].dest + 1;
    std::printf("%d %d 1\n", src, dest);
  }
  return EXIT_SUCCESS;
}
