#include <bits/stdc++.h>
using namespace std;
int n, m;
int edges[200010][3];
bool vis[200010];
int dis[200010], rep[200010];
set<pair<int, int> > que;
set<int> used;
vector<int> edge[200010];
int pre[200010], work;
void addEdge(int num, int u, int v, int c) {
  edges[num][0] = u;
  edges[num][1] = v;
  edges[num][2] = c;
}
void spfa() {
  memset(vis, false, sizeof(vis));
  for (int i = 1; i <= n; ++i) {
    dis[i] = 1000000000;
    rep[i] = 1000000000;
  }
  dis[1] = 0;
  rep[1] = 0;
  vis[1] = true;
  que.clear();
  que.insert(make_pair(dis[1], 1));
  while (!que.empty()) {
    int cur = (*que.begin()).second;
    que.erase(*que.begin());
    if (cur == n) return;
    for (int i = 0; i < edge[cur].size(); ++i) {
      int num = edge[cur][i];
      int v = edges[num][1];
      if (dis[v] > dis[cur] + 1) {
        dis[v] = dis[cur] + 1;
        pre[v] = num;
        rep[v] = rep[cur] + edges[num][2];
        que.insert(make_pair(dis[v], v));
      } else {
        if (dis[v] == dis[cur] + 1) {
          if (rep[v] > rep[cur] + edges[num][2]) {
            pre[v] = num;
            rep[v] = rep[cur] + edges[num][2];
          }
        }
      }
    }
  }
}
void dfs(int cur) {
  if (cur == 1) {
    return;
  }
  int c = edges[pre[cur]][2];
  if (c) {
    cout << edges[pre[cur]][0] << " " << edges[pre[cur]][1] << " "
         << edges[pre[cur]][2] << endl;
  } else {
    used.insert(pre[cur]);
  }
  dfs(edges[pre[cur]][0]);
}
int main() {
  int u, v, c;
  while (cin >> n >> m) {
    work = 0;
    for (int i = 0; i < m; ++i) {
      scanf("%d%d%d", &u, &v, &c);
      if (c) {
        work++;
      }
      addEdge(2 * i, u, v, c ^ 1);
      edge[u].push_back(2 * i);
      addEdge(2 * i + 1, v, u, c ^ 1);
      edge[v].push_back(2 * i + 1);
    }
    spfa();
    cout << work - dis[n] + 2 * rep[n] << endl;
    used.clear();
    dfs(n);
    for (int i = 0; i < m; ++i) {
      if (edges[2 * i][2]) continue;
      if ((used.find(2 * i) == used.end()) &&
          (used.find(2 * i + 1) == used.end())) {
        cout << edges[2 * i][0] << " " << edges[2 * i][1] << " "
             << edges[2 * i][2] << endl;
      }
    }
  }
  return 0;
}
