#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e5 + 5, Inf = 1e9, Mod = 1e9 + 7;
int n, m, h[Maxn], dp[Maxn], par[Maxn];
vector<pair<int, bool> > adj[Maxn], ans;
queue<int> q;
bool mrk[Maxn];
map<pair<int, int>, bool> mp;
vector<pair<pair<int, int>, bool> > e;
void Bfs(int root) {
  par[1] = -1;
  q.push(1);
  while (q.size()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < adj[v].size(); i++) {
      int u = adj[v][i].first;
      if (u == 1) continue;
      bool type = adj[v][i].second;
      if (!mrk[u]) {
        h[u] = h[v] + 1;
        mrk[u] = 1;
        dp[u] = dp[v] + type;
        par[u] = v;
        q.push(u);
      } else if (h[v] + 1 == h[u]) {
        dp[u] = min(dp[u], dp[v] + type);
        if (dp[u] == dp[v] + type) par[u] = v;
      }
    }
  }
}
void Find_Ans(int v) {
  while (par[v] != -1) {
    mp[{v, par[v]}] = mp[{par[v], v}] = 1;
    v = par[v];
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    bool type;
    cin >> u >> v >> type;
    adj[v].push_back({u, !type}), adj[u].push_back({v, !type});
    e.push_back({{u, v}, type});
  }
  Bfs(1);
  Find_Ans(n);
  for (int i = 0; i < m; i++) {
    if (mp[{e[i].first.first, e[i].first.second}] != e[i].second) {
      ans.push_back({i, !e[i].second});
    }
  }
  cout << ans.size() << '\n';
  for (int i = 0; i < ans.size(); i++) {
    cout << e[ans[i].first].first.first << ' ' << e[ans[i].first].first.second
         << ' ' << ans[i].second << '\n';
  }
  return 0;
}
