#include <bits/stdc++.h>
using namespace std;
struct edge {
  int s, t, cap, nxt;
} e[10005];
int last[105], e_cnt;
void ins(int a, int b, int c) {
  e[e_cnt] = (edge){a, b, c, last[a]};
  last[a] = e_cnt++;
}
double f[105][105];
double tem[105];
void Elimination(int s) {
  printf("\n");
  for (int i = (1); i <= (s); i++) {
    if (!f[i][i])
      for (int j = (i + 1); j <= (s); j++)
        if (f[j][i]) {
          memcpy(tem, f[i], sizeof(tem));
          memcpy(f[i], f[j], sizeof(tem));
          memcpy(f[j], tem, sizeof(tem));
          break;
        }
    if (!f[i][i]) continue;
    for (int j = (1); j <= (s); j++)
      if (j != i) {
        double p = f[j][i] / f[i][i];
        for (int k = (1); k <= (s + 1); k++) f[j][k] -= f[i][k] * p;
      }
  }
  for (int i = (1); i <= (s); i++) f[i][s + 1] /= f[i][i];
}
void debug() { freopen("a.in", "r", stdin); }
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  memset(last, -1, sizeof(last));
  for (int i = (1); i <= (m); i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    ins(x, y, z);
    ins(y, x, z);
  }
  for (int i = (2); i <= (n - 1); i++)
    for (int k = last[i]; k != -1; k = e[k].nxt) {
      if (e[k].t != n) f[i][e[k].t]++;
      f[i][i]--;
    }
  f[1][1] = f[1][n] = 1;
  Elimination(n - 1);
  double p = 10000000;
  for (int i = (1); i <= (n - 1); i++)
    for (int k = last[i]; k != -1; k = e[k].nxt) {
      p = min(p, e[k].cap / fabs(f[i][n] - f[e[k].t][n]));
    }
  double ans = 0;
  for (int k = last[1]; k != -1; k = e[k].nxt) ans += f[1][n] - f[e[k].t][n];
  ans *= p;
  printf("%.10f\n", ans);
  for (int i = (0); i <= (m - 1); i++)
    if ((f[e[2 * i].s][n] - f[e[2 * i].t][n]) * 0 <= (1e-8))
      printf("%.10f\n", p * (f[e[2 * i].s][n] - f[e[2 * i].t][n]));
    else
      printf("0\n");
  return 0;
}
