Cod sursa(job #1795109)

Utilizator StarGold2Emanuel Nrx StarGold2 Data 1 noiembrie 2016 23:34:33
Problema Tunelul groazei Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#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-7;

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; }
            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; }