#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 + 10, MAXM = 5000 + 10;
const double EPS = 1e-12;
double B[MAXN][MAXN], first[MAXN], Tohka;
int n, m, a[MAXM], b[MAXM], c[MAXM];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d", &a[i], &b[i], &c[i]);
    ++B[a[i]][a[i]], --B[a[i]][b[i]];
    ++B[b[i]][b[i]], --B[b[i]][a[i]];
  }
  for (int i = 1; i <= n; ++i) B[i][1] = 0;
  B[n][n + 1] = -1;
  for (int i = 2; i <= n; ++i) {
    int p = i;
    for (int j = i + 1; j <= n; ++j)
      if (fabs(B[j][i]) > fabs(B[p][i])) p = j;
    if (fabs(B[p][i]) < EPS) continue;
    for (int j = i; j <= n + 1; ++j) swap(B[i][j], B[p][j]);
    for (int j = i + 1; j <= n; ++j) {
      double t = B[j][i] / B[i][i];
      for (int k = i; k <= n + 1; ++k) B[j][k] -= B[i][k] * t;
    }
  }
  Tohka = 1e9;
  if (fabs(B[n][n]) > EPS)
    first[n] = B[n][n + 1] / B[n][n];
  else
    Tohka = 0;
  for (int i = n - 1; i >= 2; --i) {
    if (fabs(B[i][i]) < EPS) continue;
    for (int j = i + 1; j <= n; ++j) B[i][n + 1] -= B[i][j] * first[j];
    first[i] = B[i][n + 1] / B[i][i];
  }
  for (int i = 1; i <= m; ++i) {
    if (fabs(first[a[i]] - first[b[i]]) > EPS)
      Tohka = min(Tohka, c[i] / fabs(first[a[i]] - first[b[i]]));
  }
  printf("%.10lf\n", Tohka);
  for (int i = 1; i <= m; ++i)
    printf("%.10lf\n", Tohka * (first[a[i]] - first[b[i]]));
  fclose(stdin);
  fclose(stdout);
  return 0;
}
