#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> v[108];
int appear[108];
pair<int, int> roads[5008];
double cap[5008];
int et;
double xx[108];
double op[108][108];
double minxn = -1231456789.00, maxxn = 123456789.00;
void build() {
  for (int i = 2; i <= n - 1; i++) {
    for (int j = 0; j < v[i].size(); j++) {
      int q = v[i][j];
      int a = roads[q].first, b = roads[q].second;
      if (a != i)
        op[i][a] += (double)1;
      else
        op[i][b] += (double)1;
    }
    op[i][i] = -(double)v[i].size();
  }
}
void eraser(int t) {
  for (int i = n; i >= t; i--) {
    if (op[t][t] != 0) op[t][i] = op[t][i] / op[t][t];
  }
  for (int i = 1; i <= n; i++) {
    if (i == t) continue;
    double q = op[i][t];
    for (int j = 1; j <= n; j++) {
      op[i][j] -= q * op[t][j];
    }
  }
}
void solve() {
  for (int i = 2; i <= n - 1; i++) {
    if (appear[i]) eraser(i);
  }
  for (int i = 2; i <= n - 1; i++) {
    if (appear[i]) xx[i] = -op[i][n];
  }
  xx[n] = 1;
  for (int i = 0; i < et; i++) {
    int a = roads[i].first, b = roads[i].second;
    double w = xx[a] - xx[b];
    double c = cap[i];
    double l = c, r = -c;
    if (w == 0) continue;
    minxn = max(minxn, min(l / w, r / w));
    maxxn = min(maxxn, max(l / w, r / w));
  }
  if (minxn == -123456789 and maxxn == 12456789) minxn = maxxn = 0;
  double axx = 0;
  for (int i = 0; i < v[1].size(); i++) {
    int q = v[1][i];
    int a = roads[q].first, b = roads[q].second;
    if (a != 1) swap(a, b);
    axx += 0 - xx[b];
  }
  double finalx = 0;
  if (axx >= 0) {
    finalx = maxxn;
  } else {
    finalx = minxn;
  }
  cout << fixed << setprecision(7) << axx * finalx << endl;
  for (int i = 0; i < et; i++) {
    int a = roads[i].first, b = roads[i].second;
    cout << fixed << setprecision(7) << xx[a] * finalx - xx[b] * finalx << endl;
  }
}
int main() {
  cin >> n >> m;
  if (n == 2) {
    double ans = 1846565890;
    for (int i = 0; i < m; i++) {
      int a, b;
      double c;
      cin >> a >> b >> c;
      roads[et] = (make_pair(a, b));
      et++;
      ans = min(ans, abs(c));
    }
    cout << ans * m << endl;
    for (int i = 0; i < m; i++) {
      if (roads[i].first == 1)
        cout << ans;
      else
        cout << -ans;
      cout << endl;
    }
    return 0;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    double c;
    cin >> a >> b >> c;
    appear[a]++, appear[b]++;
    v[a].push_back(et);
    v[b].push_back(et);
    roads[et] = (make_pair(a, b));
    cap[et] = (c);
    et++;
  }
  build();
  solve();
  return 0;
}
