#include <bits/stdc++.h>
using namespace std;
const int N = 110, M = 5010;
const double eps = 1e-9;
int n, m;
struct eset {
  int u, v, w;
} e[M];
double c[N][N], x[N];
void setx(int i, int v) {
  memset(c[i], 0, sizeof(c[i]));
  c[i][i]++, c[i][0] = v;
}
void gauss() {
  for (int i = 1; i <= n; i++) {
    int id = i;
    for (int ii = i; ii <= n; ii++)
      if (fabs(c[ii][i]) > fabs(c[id][i])) id = ii;
    if (fabs(c[id][i]) < eps) continue;
    for (int j = i; j <= n; j++) swap(c[i][j], c[id][j]);
    swap(c[i][0], c[id][0]);
    for (int ii = i + 1; ii <= n; ii++)
      if (fabs(c[ii][i]) >= eps) {
        c[ii][0] -= c[i][0] * (c[ii][i] / c[i][i]);
        for (int j = n; j >= i; j--) c[ii][j] -= c[i][j] * (c[ii][i] / c[i][i]);
      }
  }
  for (int i = n; i >= 1; i--) {
    if (fabs(c[i][i]) < eps) continue;
    double tmp = c[i][0];
    for (int j = i + 1; j <= n; j++) tmp -= c[i][j] * x[j];
    x[i] = tmp / c[i][i];
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    e[i] = (eset){u, v, w};
    c[u][u]++, c[u][v]--;
    c[v][v]++, c[v][u]--;
  }
  setx(1, 0);
  setx(n, 1);
  gauss();
  double ans = 0, t = 1e9;
  for (int i = 1; i <= m; i++) {
    double dx = x[e[i].v] - x[e[i].u];
    t = min(t, e[i].w / fabs(dx));
    if (e[i].u == 1) ans += dx;
    if (e[i].v == 1) ans -= dx;
  }
  printf("%lf\n", ans * t);
  for (int i = 1; i <= m; i++) {
    printf("%lf\n", t * (x[e[i].v] - x[e[i].u]));
  }
}
