#include <bits/stdc++.h>
using namespace std;
const int maxn = 109, maxm = 10009;
const double EPS = 1e-8;
double x[maxn], a[maxn][maxn];
void guass(int n) {
  for (int i = 1; i <= n; i++) {
    int j = -1;
    for (int k = i; k <= n; k++) {
      if (abs(a[k][i]) > EPS) {
        j = k;
        break;
      }
    }
    if (j == -1) continue;
    if (i != j)
      for (int k = i; k <= n + 1; k++) swap(a[i][k], a[j][k]);
    for (int k = i + 1; k <= n; k++) {
      double x = a[i][i], y = a[k][i];
      if (abs(y) < EPS) continue;
      for (int p = i; p <= n + 1; p++) {
        a[k][p] = a[i][p] - x / y * a[k][p];
      }
    }
  }
  for (int i = n; i >= 1; i--) {
    double tmp = 0;
    for (int j = i + 1; j <= n; j++) {
      tmp += a[i][j] * x[j];
    }
    tmp = a[i][n + 1] - tmp;
    if (abs(a[i][i]) > EPS)
      x[i] = tmp / a[i][i];
    else {
    }
  }
}
int u[maxm], v[maxm];
double val[maxm];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int &U = u[i], &V = v[i];
    scanf("%d%d%lf", &U, &V, val + i);
    if (U < n && U > 1) a[U][V]--, a[U][U]++;
    if (V < n && V > 1) a[V][U]--, a[V][V]++;
  }
  a[1][1] = a[n][n] = 1;
  a[1][n + 1] = 1;
  a[n][n + 1] = 2;
  guass(n);
  double mul = 1e18;
  for (int i = 1; i <= m; i++) {
    int &U = u[i], &V = v[i];
    mul = min(mul, val[i] / fabs(x[U] - x[V]));
  }
  if (mul >= 1e18) mul = 0;
  double ans = 0;
  for (int i = 1; i <= m; i++) {
    int &U = u[i], &V = v[i];
    val[i] = -(x[U] - x[V]) * mul;
    if (U == 1 || V == 1) ans += fabs(val[i]);
  }
  printf("%.10f\n", ans);
  for (int i = 1; i <= m; i++) {
    printf("%.10f\n", val[i]);
  }
}
