为1
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<vector> #include<map> #include<algorithm> #define INF 10000007 using namespace std; int n,m,a,b; double c,v[101],dis[101][101],num[101][101]; int main() { scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) { dis[i][j]=INF; num[i][j]=0; } for (int i=1;i<=m;i++) { scanf("%d%d%lf",&a,&b,&c); dis[a][b]=c; dis[b][a]=c; num[a][b]=1; num[b][a]=1; } for (int k=1;k<=n;k++) for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) { if (dis[i][j]>dis[i][k]+dis[k][j]) { dis[i][j]=dis[i][k]+dis[k][j]; num[i][j]=0; } if (dis[i][j]==dis[i][k]+dis[k][j]) num[i][j]+=num[i][k]*num[k][j]; } for (int i=1;i<=n;i++) num[i][i]=0; for (int k=1;k<=n;k++) for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if (dis[i][k]+dis[k][j]==dis[i][j]&&num[i][j]!=0) v[k]+=num[i][k]*num[k][j]/num[i][j]; for (int i=1;i<=n;i++) printf("%.3lf\n",v[i]); return 0; }
原文:http://www.cnblogs.com/ws-fqk/p/4647513.html