#include <bits/stdc++.h>
using namespace std;
void _print() { cout << '\n'; }
template <typename T, typename... Ts>
void _print(const T& value, const Ts&... values) {
  cout << ' ' << value;
  _print(values...);
}
template <typename T, typename... Ts>
void print(const T& value, const Ts&... values) {
  cout << value;
  _print(values...);
}
const long long N = 1e5 + 5;
struct State {
  long long u, dis, use;
  bool operator<(const State& that) const {
    if (dis != that.dis) return dis > that.dis;
    return use < that.use;
  }
};
long long n, m;
pair<long long, long long> dis[N];
pair<long long, long long> trace[N];
vector<pair<long long, long long> > a[N];
long long usable = 0;
void dijkstra() {
  memset(dis, 127, sizeof(dis));
  dis[1] = {0, 0};
  priority_queue<State> pq;
  dis[1] = {0, 0};
  pq.push({1, dis[1].first, dis[1].second});
  while (!pq.empty()) {
    auto [u, d1, d2] = pq.top();
    pq.pop();
    if (make_pair(d1, d2) != dis[u]) continue;
    for (auto [v, s] : a[u]) {
      if (dis[v].first > dis[u].first + 1 ||
          (dis[v].first == dis[u].first + 1 &&
           dis[v].second < dis[u].second + s)) {
        dis[v].first = dis[u].first + 1;
        dis[v].second = dis[u].second + s;
        pq.push({v, dis[v].first, dis[v].second});
        trace[v] = {u, s};
      }
    }
  }
}
map<pair<long long, long long>, long long> bef, aft;
void doTrace() {
  long long u = n;
  while (u != 1) {
    long long v = trace[u].first;
    aft[minmax(u, v)] = 1;
    u = v;
  }
  cout << usable - (2 * dis[n].second - dis[n].first) << '\n';
  for (auto it : bef) {
    if (aft.find(it.first) != aft.end()) {
      if (it.second == 0)
        cout << it.first.first << ' ' << it.first.second << ' ' << 1 << '\n';
    } else {
      if (it.second == 1)
        cout << it.first.first << ' ' << it.first.second << ' ' << 0 << '\n';
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = (1); i <= (m); i++) {
    long long u, v, s;
    cin >> u >> v >> s;
    a[u].push_back({v, s});
    a[v].push_back({u, s});
    bef[minmax(u, v)] = s;
    usable += s;
  }
  dijkstra();
  doTrace();
}
