# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
3110 | tncks0121 | Following Flow (kriii1_F) | C++98 | 0 ms | 1108 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |