Pagini recente » Cod sursa (job #156514) | Cod sursa (job #2076087) | Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #1523770)
#include <bits/stdc++.h>
using namespace std;
const int nmax = 270;
double c[nmax][nmax], a[nmax];
int main()
{
freopen("tunel.in", "r", stdin);
freopen("tunel.out", "w", stdout);
int n, m, i, j, k, x, y, cost;
scanf("%d %d", &n, &m);
for(i=1; i<=m; i++)
{
scanf("%d %d %d", &x, &y, &cost);
c[x][y]+=1;
c[y][x]+=1;
a[x]+=1;
a[y]+=1;
c[x][0] += (double)cost;
c[y][0] += (double)cost;
}
for(i=1; i<n; i++)
for(j=0; j<n; j++)
c[i][j]=c[i][j]/a[i];
for(i=2; i<n; i++)
for(j=1; j<n; j++)
for(k=0; k<n; k++)
if(j!=i && k!=i)
c[j][k]+=c[i][k]* 1/(1-c[i][i])*c[j][i];
printf("%lf\n", (1.0/(1.0-c[1][1]))*c[1][0]);
fclose(stdin);
fclose(stdout);
return 0;
}