#include <bits/stdc++.h>
using namespace std;
int dr[] = {0, 0, 1, -1, -1, -1, 1, 1};
int dc[] = {1, -1, 0, 0, -1, 1, -1, 1};
const int MAX = 4 * 1e5 + 7;
struct EDGE {
  int indx, weight, z;
  EDGE(int i, int w, int x) : indx(i), weight(w), z(x){};
  bool operator<(EDGE e) const {
    if (e.weight == weight) return e.z > z;
    return e.weight < weight;
  }
};
struct ed {
  int a, b, z;
  ed(int aa = 0, int bb = 0, int zz = 0) : a(aa), b(bb), z(zz){};
};
vector<vector<pair<long long, long long>>> G;
vector<int> dis;
vector<int> pre;
map<pair<long long, long long>, int> used;
int n;
ed edges[MAX];
vector<int> dis2;
void Dijkstra() {
  priority_queue<EDGE> q;
  q.push(EDGE(0, 0, 0));
  vector<int> vis(n, 0);
  dis.resize(n, 1e9);
  pre.resize(n, -1);
  dis[0] = 0;
  dis2.resize(n, 0);
  while (!q.empty()) {
    EDGE cur = q.top();
    q.pop();
    if (vis[cur.indx]) continue;
    vis[cur.indx] = 1;
    for (int i = 0; i < (long long)G[cur.indx].size(); ++i) {
      pair<long long, long long> child = G[cur.indx][i];
      if (dis[child.first] > dis[cur.indx] + 1) {
        dis[child.first] = dis[cur.indx] + 1;
        dis2[child.first] = cur.z + child.second;
        pre[child.first] = cur.indx;
        q.push(EDGE(child.first, dis[child.first], dis2[child.first]));
      } else if (dis[child.first] == dis[cur.indx] + 1 &&
                 dis2[child.first] < cur.z + child.second) {
        pre[child.first] = cur.indx;
        dis2[child.first] += child.second;
        q.push(EDGE(child.first, dis[child.first], dis2[child.first]));
      }
    }
  }
  vector<int> path;
  int u = n - 1;
  path.push_back(u);
  while (pre[u] != 0) {
    u = pre[u];
    path.push_back(u);
  }
  path.push_back(0);
  reverse(path.begin(), path.end());
  for (int i = 0; i < (long long)path.size() - 1; ++i) {
    used[pair<long long, long long>(min(path[i], path[i + 1]),
                                    max(path[i], path[i + 1]))] = 1;
  }
}
int main() {
  int m;
  cin >> n >> m;
  G.resize(n);
  for (int i = 0; i < m; ++i) {
    int a, b, z;
    cin >> a >> b >> z;
    --a, --b;
    G[a].push_back(pair<long long, long long>(b, z));
    G[b].push_back(pair<long long, long long>(a, z));
    edges[i].a = min(a, b);
    edges[i].b = max(a, b);
    edges[i].z = z;
  }
  Dijkstra();
  vector<ed> ans;
  for (int i = 0; i < m; ++i) {
    if (used[pair<long long, long long>(edges[i].a, edges[i].b)]) {
      if (edges[i].z == 0) ans.push_back(ed(edges[i].a, edges[i].b, 1));
    } else {
      if (edges[i].z) ans.push_back(ed(edges[i].a, edges[i].b, 0));
    }
  }
  cout << (long long)ans.size() << "\n";
  for (int i = 0; i < (long long)ans.size(); ++i)
    cout << ans[i].a + 1 << " " << ans[i].b + 1 << " " << ans[i].z << "\n";
}
