标签:
为1
1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 const int N=110,inf=1000000000; 5 double a[N][N]; 6 int n,m,u,v; 7 double ans[N],map[N][N],w; 8 int main(){ 9 scanf("%d%d",&n,&m); 10 for(int i=1;i<=n;i++) 11 for(int j=1;j<=n;j++) map[i][j]=(inf+0.0); 12 for(int i=1;i<=m;i++){ 13 scanf("%d%d%lf",&u,&v,&w); 14 map[u][v]=map[v][u]=(w+0.0); 15 a[u][v]=a[v][u]=1; 16 } 17 for(int k=1;k<=n;k++) 18 for(int i=1;i<=n;i++) 19 for(int j=1;j<=n;j++){ 20 if (map[i][j]>map[i][k]+map[k][j])map[i][j]=map[i][k]+map[k][j],a[i][j]=0;; 21 if (map[i][j]==(map[i][k]+map[k][j])) a[i][j]+=a[i][k]*a[k][j]; 22 } 23 for(int i=1;i<=n;i++)a[i][i]=0; 24 for(int k=1;k<=n;k++) 25 for(int i=1;i<=n;i++) 26 for(int j=1;j<=n;j++){ 27 if (map[i][j]==(map[i][k]+map[k][j])&&a[i][j]>0) 28 ans[k]+=a[i][k]*a[k][j]/(a[i][j]+0.0); 29 } 30 for(int i=1;i<=n;i++) printf("%.3lf\n",ans[i]); 31 }
标签:
原文地址:http://www.cnblogs.com/wuminyan/p/5202605.html