#include <bits/stdc++.h>
using namespace std;
const int N = 105, M = 5005;
int n, m, x[M], y[M], w[M];
double f[N], a[N][N];
void gauss() {
  for (int i = (int)(1); i <= (int)(n); i++) {
    int j;
    for (j = i; j <= n && !a[j][i]; j++)
      ;
    if (j > n) continue;
    if (j != i)
      for (int k = (int)(i); k <= (int)(n + 1); k++) swap(a[i][k], a[j][k]);
    for (int j = (int)(i + 1); j <= (int)(n); j++) {
      double t = a[j][i] / a[i][i];
      for (int k = (int)(i); k <= (int)(n + 1); k++) a[j][k] -= t * a[i][k];
    }
  }
  for (int i = (int)(n); i >= (int)(1); i--) {
    for (int j = (int)(i + 1); j <= (int)(n); j++)
      a[i][n + 1] -= f[j] * a[i][j];
    if (a[i][i]) f[i] = a[i][n + 1] / a[i][i];
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (int)(1); i <= (int)(m); i++) {
    scanf("%d%d%d", &x[i], &y[i], &w[i]);
    if (x[i] != 1 && x[i] != n) a[x[i]][y[i]]--, a[x[i]][x[i]]++;
    if (y[i] != 1 && y[i] != n) a[y[i]][x[i]]--, a[y[i]][y[i]]++;
  }
  a[1][1] = a[n][n] = a[n][n + 1] = 1;
  gauss();
  double mn = 1e16, ans;
  for (int i = (int)(1); i <= (int)(m); i++) {
    double tmp = f[y[i]] - f[x[i]];
    mn = min(mn, abs(w[i] / tmp));
  }
  if (mn > 1e7) mn = 0;
  for (int i = (int)(1); i <= (int)(m); i++)
    if (x[i] == 1 || y[i] == 1) ans += f[y[i] * x[i]] * mn;
  printf("%.7lf\n", ans);
  for (int i = (int)(1); i <= (int)(m); i++)
    printf("%.7lf\n", (f[y[i]] - f[x[i]]) * mn);
}
