#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const int maxn = 100, maxm = 5000;
double f[maxn + 5][maxn + 5];
int n, m;
int e[maxn + 5][maxn + 5];
pair<int, pair<int, int> > ee[maxm + 5];
double first[maxn + 5];
bool vis[maxn + 5];
void dfs(const int &first) {
  if (vis[first]) return;
  vis[first] = 1;
  for (int second = (0), _end_ = (n); second < _end_; ++second)
    if (e[first][second]) dfs(second);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (0), _end_ = (m); i < _end_; ++i) {
    static int u, v, w;
    scanf("%d%d%d", &u, &v, &w), --u, --v;
    ee[i] = make_pair(w, make_pair(u, v));
    ++e[u][v];
    ++e[v][u];
  }
  dfs(0);
  for (int i = (1), _end_ = (n - 1); i < _end_; ++i) {
    int cnt = 0;
    if (vis[i]) {
      for (int j = (0), _end_ = (n); j < _end_; ++j)
        if (e[i][j]) {
          ++cnt;
          f[i][i] += e[i][j];
          f[i][j] -= e[i][j];
        }
    }
    if (!cnt) f[i][i] = 1;
  }
  f[0][0] = 1;
  static int pos[maxn + 5];
  for (int i = (0), _end_ = (n - 1); i < _end_; ++i) pos[i] = i;
  for (int i = (0), _end_ = (n - 1); i < _end_; ++i) {
    for (int j = (i + 1), _end_ = (n - 1); j < _end_; ++j)
      if (abs(f[pos[j]][i]) > abs(f[pos[i]][i])) swap(pos[j], pos[i]);
    double tmp = 1 / f[pos[i]][i];
    for (int j = (i), _end_ = (n); j < _end_; ++j) f[pos[i]][j] *= tmp;
    for (int j = (i + 1), _end_ = (n - 1); j < _end_; ++j)
      if (abs(f[pos[j]][i]) > eps) {
        double tmp = f[pos[j]][i];
        for (int k = (i), _end_ = (n); k < _end_; ++k)
          f[pos[j]][k] -= f[pos[i]][k] * tmp;
      }
  }
  if (n > 1 && vis[n - 1]) first[n - 1] = 1;
  for (int i = n - 2; i >= 0; --i) {
    first[i] = 0;
    for (int j = n - 1; j >= i + 1; --j) first[i] -= f[pos[i]][j] * first[j];
  }
  double Min = 1e100;
  for (int i = (0), _end_ = (m); i < _end_; ++i)
    if (ee[i].second.first != ee[i].second.second &&
        abs(first[ee[i].second.second] - first[ee[i].second.first]) > eps)
      Min = min(Min, ee[i].first / abs(first[ee[i].second.second] -
                                       first[ee[i].second.first]));
  double cnt = 0;
  for (int i = (0), _end_ = (m); i < _end_; ++i)
    if (ee[i].second.first == 0 && ee[i].second.second == 0)
      cnt += ee[i].first;
    else if (ee[i].second.first == 0)
      cnt += (first[ee[i].second.second] - first[ee[i].second.first]) * Min;
    else if (ee[i].second.second == 0)
      cnt += (first[ee[i].second.first] - first[ee[i].second.second]) * Min;
  printf("%.15lf\n", cnt);
  for (int i = (0), _end_ = (m); i < _end_; ++i) {
    if (ee[i].second.first != ee[i].second.second)
      printf("%.15lf\n",
             (first[ee[i].second.second] - first[ee[i].second.first]) * Min);
    else
      printf("%.15lf\n", double(ee[i].first));
  }
  return 0;
}
