#include <bits/stdc++.h>
using namespace std;
const int maxn = 200 + 10;
const double eps = 1e-5;
int n, m;
double a[maxn][maxn], f[maxn];
struct node {
  int u, v, c;
} e[5010];
void gauss() {
  for (int i = 1; i <= n; i++) {
    int j = i;
    while (fabs(a[j][i]) < eps && j <= n) j++;
    if (j > n) continue;
    if (j != i)
      for (int k = 1; k <= n + 1; k++) swap(a[i][k], a[j][k]);
    for (int j = 1; j <= n; j++) {
      if (j == i) continue;
      double t = a[j][i] / a[i][i];
      for (int k = 1; k <= n + 1; k++) a[j][k] -= t * a[i][k];
    }
  }
  for (int i = 1; i <= n; i++)
    if (a[i][i]) f[i] = a[i][n + 1] / a[i][i];
}
int main() {
  scanf("%d%d", &n, &m);
  a[1][1] = a[n][n] = a[n][n + 1] = 1;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].c);
    if (e[i].u != 1 && e[i].u != n) {
      a[e[i].u][e[i].v]--;
      a[e[i].u][e[i].u]++;
    }
    if (e[i].v != n && e[i].v != 1) {
      a[e[i].v][e[i].u]--;
      a[e[i].v][e[i].v]++;
    }
  }
  gauss();
  double mini = 1000000000, ans = 0;
  for (int i = 1; i <= m; i++)
    mini = min(mini, e[i].c / fabs(f[e[i].u] - f[e[i].v]));
  if (mini >= 100000000) mini = 0;
  for (int i = 1; i <= m; i++) {
    int u = e[i].u, v = e[i].v;
    if (v == 1)
      ans += f[u] * mini;
    else if (u == 1)
      ans += f[v] * mini;
  }
  printf("%.7lf\n", ans);
  for (int i = 1; i <= m; i++)
    printf("%.7lf\n", (f[e[i].v] - f[e[i].u]) * mini);
  return 0;
}
