题目链接
坑了好久(放寒假没做题嘿嘿嘿)
用s[i][j]表示i到j的路径数在floyd的时候计算就可以了
注意更新最短路的时候要把s[i][j]清0!!!
1 #include<algorithm> 2 #include<iostream> 3 #include<cstdlib> 4 #include<cstring> 5 #include<cstdio> 6 #include<string> 7 #include<cmath> 8 #include<ctime> 9 #include<queue> 10 #include<stack> 11 #include<map> 12 #include<set> 13 #define rre(i,r,l) for(int i=(r);i>=(l);i--) 14 #define re(i,l,r) for(int i=(l);i<=(r);i++) 15 #define Clear(a,b) memset(a,b,sizeof(a)) 16 #define inout(x) printf("%d",(x)) 17 #define douin(x) scanf("%lf",&x) 18 #define strin(x) scanf("%s",(x)) 19 #define LLin(x) scanf("%lld",&x) 20 #define op operator 21 #define CSC main 22 typedef unsigned long long ULL; 23 typedef const int cint; 24 typedef long long LL; 25 using namespace std; 26 const double inf=1e15; 27 void inin(int &ret) 28 { 29 ret=0;int f=0;char ch=getchar(); 30 while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar();} 31 while(ch>='0'&&ch<='9')ret*=10,ret+=ch-'0',ch=getchar(); 32 ret=f?-ret:ret; 33 } 34 int n,m; 35 double a[111][111],s[111][111],ans[111]; 36 int CSC() 37 { 38 freopen("in.in","r",stdin); 39 freopen("out.out","w",stdout); 40 inin(n),inin(m); 41 re(i,1,n)re(j,1,n)a[i][j]=inf; 42 re(i,1,m) 43 { 44 int q,w,e; 45 inin(q),inin(w),inin(e); 46 a[q][w]=a[w][q]=e,s[q][w]=s[w][q]=1; 47 } 48 re(i,1,n)re(j,1, n)re(k,1,n) 49 { 50 if(a[j][k]>a[j][i]+a[i][k])a[j][k]=a[j][i]+a[i][k],s[j][k]=0; 51 if(a[j][k]==a[j][i]+a[i][k])s[j][k]+=s[j][i]*s[i][k]; 52 }re(i,1,n)s[i][i]=0; 53 // re(i,1,n)re(j,1,n)printf("%.3f\n",s[i][j]); 54 re(i,1,n)re(j,1,n)re(k,1,n) 55 if(s[j][k]&&a[j][k]==a[j][i]+a[i][k]) 56 ans[i]+=s[j][i]*s[i][k]/s[j][k]; 57 re(i,1,n)printf("%.3f\n",ans[i]); 58 return 0; 59 }