Pagini recente » Cod sursa (job #2106076) | Istoria paginii runda/div1/clasament | Cod sursa (job #1509764) | Istoria paginii utilizator/el_nucu | Cod sursa (job #1750607)
#include<fstream>
#include<iomanip>
#define eps 0.0000000001
using namespace std;
int n, m, x, y, i, j, ii, jj;
int d[105][105], viz[105];
double z, c[105][105], f[105][105], a[105][105], s[105], sol;
ifstream fin("flux.in");
ofstream fout("flux.out");
double modul(double x){
if(x > 0){
return x;
}
return -x;
}
void dfs(int nod){
viz[nod] = 1;
for(int i = 1; i <= n; i++){
f[nod][i] = s[i] - s[nod];
if(viz[i] == 0){
dfs(i);
}
}
}
int main(){
fin>> n >> m;
for(i = 1; i <= n; i++){
for(j = 1; j <= n; j++){
c[i][j] = 1000000;
}
}
for(i = 1; i <= m; i++){
fin>> x >> y >> z;
c[x][y] = c[y][x] = min(c[x][y], z);
d[x][y]++;
d[y][x]++;
}
for(i = 2; i <= n; i++){
for(j = 1; j <= n; j++){
if(i != j){
a[i][j] = d[i][j];
a[i][i] -= d[i][j];
}
}
}
a[n][n + 1] = 1;
i = 2;
j = 2;
while(i <= n && j <= n){
for(ii = i; ii <= n; ii++){
if(modul(a[i][j]) >= eps){
break;
}
}
if(ii == n + 1){
j++;
continue;
}
if(ii != i){
for(jj = j; jj <= n + 1; jj++){
swap(a[i][jj], a[ii][jj]);
}
}
for(jj = j + 1; jj <= n + 1; jj++){
a[i][jj] /= a[i][j];
}
a[i][j] = 1;
for(ii = i + 1; ii <= n; ii++){
for(jj = j + 1; jj <= n + 1; jj++){
a[ii][jj] -= a[i][jj] * a[ii][j];
}
a[ii][j] = 0;
}
i++;
j++;
}
for(i = n; i >= 2; i--){
for(j = 2; j <= n + 1; j++){
if(modul(a[i][j]) >= eps){
break;
}
}
s[j] = a[i][n + 1];
for(jj = n; jj > j; jj--){
s[j] -= a[i][jj] * s[jj];
}
}
dfs(1);
sol = 1000000000;
for(i = 1; i <= n; i++){
for(j = 1; j <= n; j++){
if(d[i][j] != 0 && f[i][j] > 0){
sol = min(sol, c[i][j] / f[i][j]);
}
}
}
fout<< setprecision(3) << fixed << sol <<"\n";
return 0;
}