/**
 * Author: Sergey Kopeliovich (Burunduk30@gmail.com)
 */

#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>

#include <algorithm>
#include <vector>

using namespace std;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define sz(a) (int)(a).size()
#define pb push_back

typedef double dbl;
typedef vector <int> vi;

#define NAME "flow"

const int maxE = 2000;
const int maxV = 100;
const int maxM = maxE + maxV;
const int maxN = maxE + maxE;
const dbl eps = 1e-9;

int V, E, cap[maxE];
vi in[maxV], out[maxV];

int n, m, p[maxM], u[maxN];
dbl a[maxM][maxN + 1], c[maxN], x[maxN];
     
void Do( int i, int rj )
{
  dbl x = a[i][rj];
  forn(j, n + 1)
    a[i][j] /= x;
  forn(row, m)
    if (row != i && fabs(x = a[row][rj]) > eps)
      forn(j, n + 1)
        a[row][j] -= a[i][j] * x;
}

int main()
{
  assert(freopen(NAME ".in", "r", stdin));
  assert(freopen(NAME ".out", "w", stdout));

  scanf("%d%d", &V, &E);
  E *= 2;
  assert(E <= maxE && V <= maxV);
  forn(i, E)
  {
    int a, b;
    scanf("%d%d%d", &a, &b, &cap[i]), a--, b--;
    out[a].pb(i), in[b].pb(i);

    i++, cap[i] = cap[i - 1];
    out[b].pb(i), in[a].pb(i);
  }

  int start = 0, end = V - 1;
  m = E, n = 2 * E;
  forn(i, E)
    a[i][i] = a[i][i + E] = 1, a[i][n] = cap[i];
  forn(i, V)
    if (i != start && i != end)
    {
      forn(j, sz(in[i]))
        a[m][E + in[i][j]] = 1;
      forn(j, sz(out[i]))
        a[m][E + out[i][j]] = -1;
      m++;
    }
  forn(j, sz(in[start]))
    c[E + in[start][j]] = -1;
  forn(j, sz(out[start]))
    c[E + out[start][j]] = 1;
  
  forn(i, m)
  {
    int rj = -1;
    forn(j, n)
      if (!u[j] && fabs(a[i][j]) > eps)
        rj = j, j = n;
    if (rj == -1)
      memcpy(a[i], a[--m], sizeof(a[0])), i--;
    else
      p[i] = rj, u[rj] = 1, Do(i, rj);
  }

  int run = 1;
  while (run)
  {
    run = 0;
    forn(j, n)
      if (!u[j])
      {
        dbl dc = c[j];
        forn(i, m)
          dc -= a[i][j] * c[p[i]];
        if (dc > eps)
        {
          dbl MAX = 1e100, tmp;
          int ri = -1;
          forn(i, m)
            if (a[i][j] > eps && MAX > (tmp = a[i][n] / a[i][j]))
              MAX = tmp, ri = i;

          int j0 = p[ri];
          p[ri] = j, u[j] = 1, u[j0] = 0;
          Do(ri, j);
          run = 1, j = n;
        }
      }
  }

  dbl res = 0;
  forn(i, m)
    x[p[i]] = a[i][n];
  forn(i, n)
    res += x[i] * c[i];
  printf("%.20lf\n", (double)res);
  forn(i, E)
    printf("%.20lf\n", x[E + i] - x[E + i + 1]), i++;
  return 0;
}