#include <bits/stdc++.h>
using namespace std;
int N, M, a[10005], b[10005], c[10005], d[105][105];
double f[105][105], x[105];
void init() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= M; i++)
    scanf("%d%d%d", &a[i], &b[i], &c[i]), d[a[i]][b[i]]++, d[b[i]][a[i]]++;
}
void Gauss() {
  for (int i = 1; i <= N; i++) {
    for (int j = i; j <= N; j++)
      if (abs(f[j][i]) > 1e-9) {
        for (int k = 0; k <= N; k++) swap(f[i][k], f[j][k]);
        break;
      }
    for (int j = i + 1; j <= N; j++)
      if (abs(f[j][i]) > 1e-9) {
        double x = f[j][i] / f[i][i];
        for (int k = 0; k <= N; k++) f[j][k] -= f[i][k] * x;
      }
  }
  for (int i = N; i; i--)
    if (abs(f[i][i]) > 1e-9) {
      x[i] = f[i][0];
      for (int j = i + 1; j <= N; j++) x[i] -= f[i][j] * x[j];
      x[i] /= f[i][i];
    }
}
void doit() {
  f[1][1] = f[N][N] = f[N][0] = 1;
  for (int i = 2; i < N; i++)
    for (int j = 1; j <= N; j++) f[i][j] += d[i][j], f[i][i] -= d[i][j];
  Gauss();
  double mi = 1e9, s = 0;
  for (int i = 1; i <= M; i++) mi = min(mi, c[i] / abs(x[b[i]] - x[a[i]]));
  for (int i = 1; i <= N; i++) s += d[i][N] * (x[N] - x[i]);
  printf("%.9lf\n", s * mi);
  for (int i = 1; i <= M; i++) printf("%.9lf\n", (x[b[i]] - x[a[i]]) * mi);
}
int main() {
  init();
  doit();
  return 0;
}
