#include <bits/stdc++.h>
using namespace std;
int V, E;
int v1[5010], v2[5010], c[5010];
int cnt[110][110];
double cap[110][110];
bool used[110];
void dfs(int x) {
  if (used[x]) return;
  used[x] = true;
  int i;
  for ((i) = 0; (i) < (int)(V); (i)++)
    if (cnt[x][i] > 0) dfs(i);
}
double a[110][110], b[110], x[110];
void linear_equation(int N) {
  int i, j, k;
  for ((i) = 0; (i) < (int)(N); (i)++) {
    int r = i;
    for (j = i + 1; j < N; j++)
      if (((a[j][i]) > 0 ? (a[j][i]) : -(a[j][i])) >
          ((a[r][i]) > 0 ? (a[r][i]) : -(a[r][i])))
        r = j;
    if (r != i) {
      for ((j) = 0; (j) < (int)(N); (j)++) swap(a[r][j], a[i][j]);
      swap(b[r], b[i]);
    }
    for ((j) = 0; (j) < (int)(N); (j)++)
      if (j != i) {
        double p = -a[j][i] / a[i][i];
        for (k = i; k < N; k++) a[j][k] += a[i][k] * p;
        b[j] += b[i] * p;
      }
  }
  for ((i) = 0; (i) < (int)(N); (i)++) x[i] = b[i] / a[i][i];
}
int main(void) {
  int i, j;
  cin >> V >> E;
  for ((i) = 0; (i) < (int)(E); (i)++) {
    cin >> v1[i] >> v2[i] >> c[i];
    v1[i]--;
    v2[i]--;
  }
  for ((i) = 0; (i) < (int)(E); (i)++) {
    cnt[v1[i]][v2[i]]++;
    cnt[v2[i]][v1[i]]++;
  }
  dfs(0);
  if (!used[V - 1]) {
    for ((i) = 0; (i) < (int)(E + 1); (i)++) cout << 0 << endl;
    return 0;
  }
  for ((i) = 0; (i) < (int)(V); (i)++)
    if (!used[i]) a[i][i] = 1.0;
  b[0] = 1.0;
  for ((i) = 0; (i) < (int)(V - 1); (i)++)
    if (used[i])
      for ((j) = 0; (j) < (int)(V); (j)++)
        if (j != i) {
          a[i][i] += cnt[i][j];
          a[i][j] -= cnt[i][j];
        }
  a[V - 1][V - 1] = 1.0;
  b[V - 1] = 0.0;
  linear_equation(V);
  for ((i) = 0; (i) < (int)(V); (i)++)
    for ((j) = 0; (j) < (int)(V); (j)++)
      if (cnt[i][j] > 0) cap[i][j] = 10000.0;
  for ((i) = 0; (i) < (int)(E); (i)++) {
    cap[v1[i]][v2[i]] = min(cap[v1[i]][v2[i]], (double)c[i]);
    cap[v2[i]][v1[i]] = min(cap[v2[i]][v1[i]], (double)c[i]);
  }
  double ans = 1.0E+9;
  for ((i) = 0; (i) < (int)(V); (i)++)
    for ((j) = 0; (j) < (int)(V); (j)++)
      if (cnt[i][j] > 0) {
        double tmp = x[i] - x[j];
        if (tmp < 0.0) tmp = -tmp;
        if (tmp > 1.0E-9) ans = min(ans, cap[i][j] / tmp);
      }
  printf("%.9f\n", ans);
  for ((i) = 0; (i) < (int)(E); (i)++)
    printf("%.9f\n", (x[v1[i]] - x[v2[i]]) * ans);
  return 0;
}
