#include <bits/stdc++.h>
using namespace std;
int n, m, a[5010], b[5010], d[110][110];
double mat[110][110], res[110], flow[110][110], c[5010], ans;
bool used[110];
void input() {
  memset(flow, 0x7f, sizeof(flow));
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> a[i] >> b[i] >> c[i];
    ++d[a[i]][b[i]], ++d[b[i]][a[i]];
    flow[a[i]][b[i]] = flow[b[i]][a[i]] = min(flow[a[i]][b[i]], c[i]);
  }
}
bool achievable(int x) {
  bool flg = (x == n);
  used[x] = 1;
  for (int i = 1; i <= n; ++i)
    if (!used[i] && d[x][i]) flg |= achievable(i);
  return flg;
}
void check() {
  if (!achievable(1)) {
    for (int i = 0; i <= m; puts("0.00000"), ++i)
      ;
    exit(0);
  }
}
void potential() {
  res[1] = 1.0, mat[n][n] = 1.0;
  for (int i = 1; i < n; ++i) {
    if (!used[i]) {
      mat[i][i] = 1.0;
      continue;
    }
    for (int j = 1; j <= n; ++j)
      if (j != i) mat[i][i] += 1.0 * d[i][j], mat[i][j] -= 1.0 * d[i][j];
  }
}
void Gauss() {
  for (int i = 1; i <= n; ++i) {
    int ind = i;
    for (int j = i + 1; j <= n; ++j)
      if (((mat[j][i]) > 0 ? (mat[j][i]) : (-mat[j][i])) >
          ((mat[ind][i]) > 0 ? (mat[ind][i]) : (-mat[ind][i])))
        ind = j;
    if (ind != i)
      for (int j = i; j <= n; ++j) swap(mat[ind][j], mat[i][j]);
    swap(res[ind], res[i]);
    for (int j = 1; j <= n; ++j) {
      if (i == j) continue;
      double ratio = -mat[j][i] / mat[i][i];
      for (int k = i; k <= n; ++k) mat[j][k] += ratio * mat[i][k];
      res[j] += ratio * res[i];
    }
  }
  for (int i = 1; i <= n; ++i)
    if (((mat[i][i]) > 0 ? (mat[i][i]) : (-mat[i][i])) > 1e-8)
      res[i] /= mat[i][i];
}
void output() {
  ans = 1.0e9;
  for (int i = 0; i < m; ++i)
    if ((((res[a[i]] - res[b[i]])) > 0 ? ((res[a[i]] - res[b[i]]))
                                       : (-(res[a[i]] - res[b[i]]))) > 1e-8)
      ans = min(ans, flow[a[i]][b[i]] / (((res[a[i]] - res[b[i]])) > 0
                                             ? ((res[a[i]] - res[b[i]]))
                                             : (-(res[a[i]] - res[b[i]]))));
  cout << fixed << setprecision(9) << ans << endl;
  for (int i = 0; i < m; ++i)
    cout << fixed << setprecision(9) << (res[a[i]] - res[b[i]]) * ans << endl;
}
int main() {
  input();
  check();
  potential();
  Gauss();
  output();
  return 0;
}
