#include<stdio.h>
int n,m,deg[31],Ed[1001][3];
double w[31][31],C[31],t,t2;
int main()
{
int i,a,b,j,k;
scanf("%d%d",&n,&m);
for(i=0;i<m;i++){
scanf("%d%d%d",&Ed[i][0],&Ed[i][1],&Ed[i][2]);
deg[Ed[i][0]]++;
}
for(i=0;i<m;i++){
a=Ed[i][0],b=Ed[i][1];
if(b!=n)w[a][b]+=1.0/deg[a];
C[a]+=1.0*Ed[i][2]/deg[a];
}
for(i=n-1;i>0;i--){
t=1.0/(1.0-w[i][i]);
w[i][i]=0;
for(j=i-1;j>=0;j--){
t2=t*w[j][i];
w[j][i]=0;
for(k=i-1;k>=0;k--){
w[j][k]+=w[i][k]*t2;
C[j]+=C[i]*t2;
}
}
}
printf("%.9lf\n",1.0/(1.0-w[0][0])*C[0]);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1108 KB |
Output is correct |
2 |
Correct |
0 ms |
1108 KB |
Output is correct |
3 |
Incorrect |
0 ms |
1108 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |