#include <bits/stdc++.h>
using namespace std;
void bug(string st = "bug") { cout << st << endl; }
const int MAXN = 100010;
struct EDGE {
  int u, v, next;
  bool del;
  bool ok;
} edge[MAXN * 3];
int head[MAXN], cnt;
int n, m, sum = 0;
int s, tot = 100000000;
int idx[MAXN], temp[MAXN];
bool vis[MAXN];
int dist[MAXN];
void addedge(int u, int v, int ok) {
  edge[cnt].u = u;
  edge[cnt].v = v;
  edge[cnt].next = head[u];
  if (ok == 1)
    edge[cnt].ok = 1;
  else
    edge[cnt].ok = 0;
  edge[cnt].del = 0;
  head[u] = cnt++;
}
void bfs() {
  bool vis[MAXN];
  for (int i = 0; i < MAXN; i++) dist[i] = 100000000;
  memset(vis, 0, sizeof(vis));
  dist[n] = 0;
  queue<int> que;
  que.push(n);
  while (!que.empty()) {
    int u = que.front();
    que.pop();
    vis[u] = 0;
    for (int i = head[u]; i != -1; i = edge[i].next) {
      int v = edge[i].v;
      if (dist[v] > dist[u] + 1) {
        dist[v] = dist[u] + 1;
        if (!vis[v]) {
          vis[v] = 1;
          que.push(v);
        }
      }
    }
  }
  s = dist[1];
}
void dfs(int u, int depth, int good, int bad) {
  if (depth + dist[u] > s) return;
  if (depth == s && u == n) {
    if (sum - good + bad < tot) {
      tot = sum - good + bad;
      for (int i = 0; i < s; i++) idx[i] = temp[i];
    }
    return;
  }
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].v;
    if (!vis[v]) {
      vis[v] = 1;
      temp[depth] = i;
      int goodtemp = good + (edge[i].ok == 1 ? 1 : 0);
      int badtemp = bad + (edge[i].ok == 0 ? 1 : 0);
      dfs(v, depth + 1, goodtemp, badtemp);
      vis[v] = 0;
    }
  }
}
int main() {
  cnt = 0;
  cin >> n >> m;
  memset(head, -1, sizeof(head));
  for (int i = 1; i <= m; i++) {
    int u, v, ok;
    cin >> u >> v >> ok;
    addedge(u, v, ok);
    addedge(v, u, ok);
    if (ok == 1) sum++;
  }
  bfs();
  memset(vis, 0, sizeof(vis));
  vis[1] = 1;
  dfs(1, 0, 0, 0);
  cout << tot << endl;
  for (int i = 0; i < s; i++) {
    bool flag = 0;
    edge[idx[i]].del = 1;
    edge[idx[i] ^ 1].del = 1;
    if (edge[idx[i]].ok == 0)
      cout << edge[idx[i]].u << " " << edge[idx[i]].v << " 1\n";
  }
  for (int i = 0; i < cnt; i += 2)
    if (!edge[i].del && edge[i].ok == 1)
      cout << edge[i].u << " " << edge[i].v << " 0\n";
  return 0;
}
