#include <bits/stdc++.h>
using namespace std;
int i, j, k, n, m, x, y;
int f[110][110], X[5010], Y[5010], Z[5010];
double a[110][110], b[110];
void gauss() {
  int i, j, k;
  for (i = 1; i <= n - 2; i++) {
    for (j = i; j <= n - 2; j++)
      if (a[j][i]) {
        for (k = i; k <= n - 1; k++) swap(a[j][k], a[i][k]);
        break;
      }
    if (a[i][i])
      for (j = n - 1; j >= i; j--) a[i][j] /= a[i][i];
    for (j = i + 1; j <= n - 1; j++)
      for (k = n - 1; k >= i; k--) a[j][k] -= a[i][k] * a[j][i];
  }
  for (i = n - 2; i; i--) {
    b[i + 1] = a[i][n - 1];
    for (j = 1; j <= i - 1; j++) a[j][n - 1] -= a[j][i] * a[i][n - 1];
  }
  b[n] = 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &Z[i]);
    f[x][y]++, f[y][x]++;
    X[i] = x, Y[i] = y;
  }
  for (i = 2; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      a[i - 1][i - 1] -= f[i][j];
      if (j > 1 && j < n) a[i - 1][j - 1] += f[i][j];
      if (j == n) a[i - 1][n - 1] -= f[i][j];
    }
  }
  gauss();
  double an = 1e9, sum = 0;
  for (i = 1; i <= m; i++) {
    x = X[i], y = Y[i];
    double s = b[x] - b[y];
    if (s < 0) s = -s;
    an = min(an, Z[i] / s);
    if (x == n || y == n) sum += s;
  }
  for (i = 1; i <= n; i++) b[i] *= an;
  printf("%.12lf\n", sum * an);
  for (i = 1; i <= m; i++) printf("%.12lf\n", b[Y[i]] - b[X[i]]);
  return 0;
}
