Pagini recente » Cod sursa (job #2477510) | Cod sursa (job #3038153) | Cod sursa (job #3001175) | Cod sursa (job #2702288) | Cod sursa (job #3140083)
#include <bits/stdc++.h>
using namespace std;
ifstream fin( "flux.in" );
ofstream fout( "flux.out" );
const int DIM = 105;
const double EPS = 1e-5;
double t[DIM][DIM];
double res[DIM];
void Gauss( int n, int m ) {
for ( int l = 1, c = 1; l <= n && c <= m; ++c ) {
int nxt = l;
while ( nxt <= n && abs( t[nxt][c] ) < EPS ) {
++nxt;
}
if ( nxt > n ) continue;
for ( int i = 1; i <= m + 1; ++i ) {
swap( t[nxt][i], t[l][i] );
}
for ( int i = c + 1; i <= m + 1; ++i ) {
t[l][i] /= t[l][c];
}
t[l][c] = 1;
for ( int nl = l + 1; nl <= n; ++nl ) {
for ( int nc = c + 1; nc <= m + 1; ++nc ) {
t[nl][nc] -= t[nl][c] * t[l][nc];
}
t[nl][c] = 0;
}
++l;
}
for ( int i = n; i > 0; --i ) {
int j = 1;
while ( j <= m && abs( t[i][j] ) < EPS ) {
++j;
}
res[j] = t[i][m + 1];
for ( int nj = j + 1; nj <= m; ++nj ) {
res[j] -= res[nj] * t[i][nj];
}
}
}
vector<pair<int, int>> G[DIM];
int main() {
int n, m, u, v, c;
fin >> n >> m;
while ( m-- ) {
fin >> u >> v >> c;
G[u].push_back({v, c});
G[v].push_back({u, c});
}
for ( u = 2; u <= n; ++u ) {
for ( auto qq : G[u] ) {
--t[u - 1][qq.first - 1];
}
t[u - 1][u - 1] += G[u].size();
if ( u == n ) {
t[u - 1][n] = 1;
}
}
Gauss(n - 1, n - 1);
double sol = 1e9;
for ( u = 1; u <= n; ++u ) {
for ( auto qq : G[u] ) {
sol = min(sol, abs((double)qq.second / (res[u - 1] - res[qq.first - 1])));
}
}
fout << setprecision(5) << fixed << sol;
fin.close();
fout.close();
return 0;
}