#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > g[100001];
bool vis[100001];
int dis[100001];
int num[100001];
int fa[100001];
int n, m;
int use[100001];
vector<pair<pair<int, int>, int> > ans;
void spfa() {
  queue<int> q;
  q.push(1);
  dis[1] = 0;
  vis[1] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = 0;
    for (int i = 0; i < g[u].size(); i++) {
      int v = g[u][i].first, value = g[u][i].second;
      if (dis[v] > dis[u] + 1 ||
          (dis[v] == dis[u] + 1 && num[v] < num[u] + value)) {
        dis[v] = dis[u] + 1;
        num[v] = num[u] + value;
        fa[v] = u;
        if (!vis[v]) {
          vis[v] = 1;
          q.push(v);
        }
      }
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    g[a].push_back(make_pair(b, c));
    g[b].push_back(make_pair(a, c));
  }
  memset(dis, 63, sizeof(dis));
  spfa();
  for (int i = n; i != 1; i = fa[i]) use[i] = 1;
  use[1] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < g[i].size(); j++) {
      if (i < g[i][j].first && (!use[i] || !use[g[i][j].first]) &&
          g[i][j].second == 1)
        ans.push_back(make_pair(make_pair(i, g[i][j].first), 0));
      if (i < g[i][j].first && use[i] && use[g[i][j].first] &&
          g[i][j].second == 0)
        ans.push_back(make_pair(make_pair(i, g[i][j].first), 1));
    }
  sort(ans.begin(), ans.end());
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first.first << " " << ans[i].first.second << " "
         << ans[i].second << endl;
  return 0;
}
