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

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

#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], b[maxM], c[maxN], dc[maxN], x[maxN];
int wn, w[maxN];
int start, cnt1, cnt2;
     
void DoSmall( int i, int rj )
{
  cnt1 += n + m;

  dbl x = a[i][rj];
  wn = 0;
  forn(j, n)
    if (fabs(a[i][j]) > eps)
      a[i][j] /= x, w[wn++] = j;
  b[i] /= x;

  forn(row, m)
    if (row != i && fabs(a[row][rj]) > eps)
    {
      cnt2 += wn;

      dbl koef = a[row][rj];
      int j;
      forn(t, wn)
        j = w[t], a[row][j] -= a[i][j] * koef;
      b[row] -= b[i] * koef;
    }
}

void Do( int i, int rj )
{
  dbl x = a[i][rj];
  wn = 0;
  forn(j, n)
    if (fabs(a[i][j]) > eps)
    {
      dc[j] += a[i][j] * c[p[i]];
      a[i][j] /= x;
      dc[j] -= a[i][j] * c[p[i]];
      w[wn++] = j;

    }
  b[i] /= x;

  forn(row, m)
    if (row != i && fabs(a[row][rj]) > eps)
    {
      dbl koef = a[row][rj];
      forn(t, wn)
      {
        int j = w[t];
        dc[j] += a[row][j] * c[p[row]];
        a[row][j] -= a[i][j] * koef;
        dc[j] -= a[row][j] * c[p[row]];
      }
      b[row] -= b[i] * koef;
    }
}

void Time()
{
  fprintf(stderr, "Time = %.2lf\n", (clock() - start) / (double)CLOCKS_PER_SEC);
}

int main()
{
  start = clock();

  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);
  }

  fprintf(stderr, "start!\n");

  int start = 0, end = V - 1;
  m = E, n = 2 * E;
  forn(i, E)
    a[i][i] = a[i][i + E] = 1, b[i] = 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;
  
  fprintf(stderr, "1 "), Time();

  forn(i, m)
  {
    if (i < E)
    {
      p[i] = i, u[i] = 1;
      continue;
    }

    int rj = -1;
    forn(j, n)
      if (!u[j] && a[i][j])
        rj = j, j = n;
    if (rj == -1)
      memcpy(a[i], a[m - 1], sizeof(a[0])), b[i--] = b[--m];
    else
      p[i] = rj, u[rj] = 1, DoSmall(i, rj);
  }

  fprintf(stderr, "2 "), Time();

  forn(j, n)
    dc[j] = c[j];
  forn(i, m)
    forn(j, n)
      dc[j] -= a[i][j] * c[p[i]];

  fprintf(stderr, "3 "), Time();

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

        int j0 = p[ri];
        p[ri] = j, u[j] = 1, u[j0] = 0;
        forn(t, n)
          dc[t] -= a[ri][t] * (c[j] - c[j0]);
        Do(ri, j);
        run = 1, j = n;
      }
  }

  fprintf(stderr, "4 "), Time();
  fprintf(stderr, "n=%d, m=%d, cnt=%d\n", n, m, cnt);
  fprintf(stderr, "cnt1 = %d\n", cnt1);
  fprintf(stderr, "cnt2 = %d\n", cnt2);

  dbl res = 0;
  forn(i, m)
    x[p[i]] = b[i];
  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;
}