Pagini recente » Cod sursa (job #3120453) | Cod sursa (job #747622) | Cod sursa (job #1222474) | Cod sursa (job #3254375) | Cod sursa (job #1795106)
#include <fstream>
#include <algorithm>
#include <cmath>
using namespace std;
ifstream in ( "tunel.in" );
ofstream out( "tunel.out" );
const int DIM = 260;
const double EPS = 1e-5;
long double sys[DIM][DIM];
int main( int argc, const char *argv[] ) {
ios::sync_with_stdio( false );
int n, m; in >> n >> m;
for( int i = 1; i <= m; i ++ ) {
int x, y, c; in >> x >> y >> c;
sys[x][x] ++; sys[x][y] --; sys[x][n + 1] += c;
sys[y][y] ++; sys[y][x] --; sys[y][n + 1] += c; }
for( int i = 1; i <= n; i ++ ) {
if( fabs( sys[i][i] ) < EPS ) {
continue; }
for( int j = 1; j <= n; j ++ ) {
if( i == j ) {
continue; }
long double aux = sys[j][i] / sys[i][i];
for( int k = 1; k <= n + 1; k ++ ) {
sys[j][k] -= sys[i][k] * aux; } } }
out << sys[1][n + 1] / sys[1][1] << endl;
return 0; }