#include <bits/stdc++.h>
using namespace std;
int T[20005];
int u[20005], v[20005], w[20005];
double f[20005], rhl, ans;
double x[105][105];
int n, m, len = 1, head[105];
struct way {
  int num, next, cap;
} G[20005];
void link(int x, int y, int z) {
  G[++len] = (way){y, head[x], z};
  head[x] = len;
}
void gauss() {
  int i, j, k;
  double v;
  for (i = 1; i <= n; i++) {
    if (x[i][i] == 0) {
      for (j = i + 1; j <= n; j++)
        if (x[j][i] != 0) break;
      for (k = 1; k <= n + 1; k++) swap(x[i][k], x[j][k]);
    }
    for (j = i + 1; j <= n; j++) {
      if (x[j][i] == 0) continue;
      v = x[j][i] * 1.0 / x[i][i];
      for (k = 1; k <= n + 1; k++) x[j][k] -= x[i][k] * v;
    }
  }
  for (i = n; i >= 1; i--) {
    x[i][n + 1] /= x[i][i];
    for (j = i - 1; j >= 1; j--)
      if (x[j][i] != 0) {
        x[j][n + 1] -= x[j][i] * x[i][n + 1];
        x[j][i] = 0;
      }
  }
}
int main() {
  int i, j;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= m; i++) T[i] = 1;
  for (i = 1; i <= m; i++) {
    scanf("%d %d %d", &u[i], &v[i], &w[i]);
    if (v[i] == 1 || u[i] == n) swap(u[i], v[i]), T[i] = -1;
    link(u[i], v[i], w[i]), link(v[i], u[i], -1);
  }
  for (i = 1; i < n; i++) {
    if (i == 1) {
      x[1][1] = 1;
      continue;
    }
    for (j = head[i]; j; j = G[j].next) x[i][i]++, x[i][G[j].num]--;
  }
  x[n][n + 1] = 1.0, x[n][n] = 1;
  gauss(), rhl = (1 << 30);
  for (i = 1; i <= m; i++) {
    f[i] = x[v[i]][n + 1] - x[u[i]][n + 1];
    rhl = min(rhl, fabs(w[i] / f[i]));
  }
  for (i = 1; i <= m; i++) {
    f[i] *= rhl;
    if (v[i] == n) ans += f[i];
  }
  printf("%.5lf\n", ans);
  for (i = 1; i <= m; i++) {
    if (f[i] != f[i]) f[i] = 0;
    printf("%.5lf\n", f[i] * T[i]);
  }
  return 0;
}
