/**
* Author: Sergey Kopeliovich (Burunduk30@gmail.com)
*/
#include <cmath>
#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 pb push_back
#define sz(a) (int)(a).size()
typedef double dbl;
typedef vector <int> vi;
#define NAME "flow"
const int maxV = 100;
const int maxE = 5000;
const int maxM = maxV - 2;
const int maxN = maxE;
const dbl eps = 1e-9;
int n, m, V, E, cap[maxE];
vi out[maxV], in[maxV];
dbl a[maxM][maxN + 1], c[maxN], x[maxN], lower[maxN], upper[maxN], df[maxN];
int w[maxN], p[maxN], u[maxN];
int cnt1 = 0;
inline void ChangeA( int i, int j, dbl val )
{
df[j] -= (val - a[i][j]) * c[p[i]], a[i][j] = val;
}
void Do( int i, int j )
{
int wn = 0;
dbl x = 1.0 / a[i][j];
forn(k, n + 1)
if (fabs(a[i][k]) > eps)
w[wn++] = k, ChangeA(i, k, a[i][k] * x);
forn(y, m) if (y != i && fabs(x = a[y][j]) > eps)
forn(k, wn)
ChangeA(y, w[k], a[y][w[k]] - x * a[i][w[k]]);
cnt1++;
}
void Change( int j, int dir, dbl val )
{
int ri = -1;
dbl ma = val;
forn(i, m)
if (fabs(a[i][j]) > eps)
{
dbl t, koef = 1.0 / (a[i][j] * dir);
t = koef * (koef > 0 ? x[p[i]] - lower[p[i]] : x[p[i]] - upper[p[i]]);
if (t < ma) ma = t, ri = i;
}
dbl dx = ma * dir;
x[j] += dx;
forn(i, m)
if (fabs(a[i][j]) > eps)
x[p[i]] -= (a[i][j] * dx) / a[i][p[i]];
if (ri != -1)
{
forn(t, n)
df[t] -= a[ri][t] * (c[j] - c[p[ri]]);
u[p[ri]] = 0, u[p[ri] = j] = 1, Do(ri, j);
}
}
int main()
{
assert(freopen(NAME ".in", "r", stdin));
assert(freopen(NAME ".out", "w", stdout));
scanf("%d%d", &V, &E);
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);
}
int start = 0, end = V - 1;
m = 0, n = E;
forn(i, E)
lower[i] = -cap[i], upper[i] = cap[i], x[i] = 0;
forn(i, V)
if (i != start && i != end)
{
forn(j, sz(in[i]))
a[m][in[i][j]] = 1;
forn(j, sz(out[i]))
a[m][out[i][j]] = -1;
m++;
}
forn(j, sz(in[start]))
c[in[start][j]] = -1;
forn(j, sz(out[start]))
c[out[start][j]] = 1;
forn(i, m)
{
int mj = -1;
forn(j, n)
if (!u[j] && fabs(a[i][j]) > eps)
mj = j, j = n;
if (mj == -1)
memcpy(a[i], a[--m], sizeof(a[i])), i--;
else
u[p[i] = mj] = 1, Do(i, mj);
}
int run = 1;
forn(j, n)
df[j] = c[j];
forn(i, m)
forn(j, n)
df[j] -= a[i][j] * c[p[i]];
while (run)
{
run = 0;
forn(j, n) if (!u[j])
{
if (df[j] > eps && x[j] + eps < upper[j])
run = 1, Change(j, 1, upper[j] - x[j]);
else if (df[j] < -eps && x[j] - eps > lower[j])
run = 1, Change(j, -1, x[j] - lower[j]);
}
}
dbl res = 0;
forn(i, n)
res += x[i] * c[i];
printf("%.20lf\n", (double)res);
forn(i, E)
printf("%.20lf\n", x[i]);
fprintf(stderr, "cnt1 = %d, V = %d, E = %d\n", cnt1, V, E);
return 0;
}