Pagini recente » Cod sursa (job #1860880) | Cod sursa (job #1172762) | Cod sursa (job #984059) | Cod sursa (job #2404346) | Cod sursa (job #2629599)
#include <bits/stdc++.h>
using namespace std;
const int DIM = 105;
const double EPS = 1e-6;
struct edge {
int x, y, c;
};
vector <edge> E;
int n, m;
double val[DIM];
double a[DIM][DIM];
void gauss() {
int c = 2;
for (int i = 2; i <= n; i++) {
int l = i;
while (l <= n && fabs(a[l][c]) < EPS)
l++;
if (l <= n) {
if (l != i)
for (int j = c; j <= n; j++)
swap(a[l][j], a[i][j]);
for (int j = c + 1; j <= n; j++)
a[i][j] /= a[i][c];
a[i][c] = 1;
for (l = i + 1; l <= n; l++) {
for (int j = c + 1; j <= n; j++)
a[l][j] -= a[l][c] * a[i][j];
a[l][c] = 0;
}
}
c++;
}
val[n] = 1;
for (int i = n - 1; i > 1; i--)
for (int j = 2; j <= n; j++)
val[i] -= val[j] * a[i][j];
}
int main()
{
freopen("flux.in", "r", stdin);
freopen("flux.out", "w", stdout);
scanf("%d%d", &n, &m);
int x, y, c;
for (int i = 1; i <= m ; ++i) {
scanf("%d%d%d", &x, &y, &c);
++a[x][y]; --a[x][x];
--a[y][y]; ++a[y][x];
E.push_back({x, y, c});
}
a[n][n + 1] = 1.0;
gauss();
double Sol = 0;
double inm = 0.0;
bool ok = false;
for (auto it : E) {
if (it.x == 1 || it.y == 1) Sol = Sol + val[it.y] + val[it.x];
if (val[it.x] == val[it.y]) continue ;
if (it.c == 0) {
printf("0");
return 0;
}
ok = true;
inm = max(inm, abs(val[it.y] - val[it.x]) / it.c);
}
if (!ok) printf("0");
else printf("%0.3f", Sol / inm);
return 0;
}