社交网络如下图所示。
对于 1 号结点而言,只有 2 号到 4 号结点和 4 号到 2 号结点的最短路经过 1 号结点,而 2 号结点和 4 号结点之间的最短路又有 2 条。因而根据定义,1 号结点的重要程度计算为 1/2 + 1/2 = 1 。由于图的对称性,其他三个结点的重要程度也都是 1 。
正解:$floyd$。
裸$floyd$最短路+计数。
1 //It is made by wfj_2048~ 2 #include <algorithm> 3 #include <iostream> 4 #include <cstring> 5 #include <cstdlib> 6 #include <cstdio> 7 #include <vector> 8 #include <cmath> 9 #include <queue> 10 #include <stack> 11 #include <map> 12 #include <set> 13 #define inf (1<<30) 14 #define N (510) 15 #define il inline 16 #define RG register 17 #define ll long long 18 19 using namespace std; 20 21 double g[N][N],ans[N]; 22 ll f[N][N],n,m; 23 24 il ll gi(){ 25 RG ll x=0,q=1; RG char ch=getchar(); 26 while ((ch<‘0‘ || ch>‘9‘) && ch!=‘-‘) ch=getchar(); 27 if (ch==‘-‘) q=-1,ch=getchar(); 28 while (ch>=‘0‘ && ch<=‘9‘) x=x*10+ch-48,ch=getchar(); 29 return q*x; 30 } 31 32 int main(){ 33 #ifndef ONLINE_JUDGE 34 freopen("network.in","r",stdin); 35 freopen("network.out","w",stdout); 36 #endif 37 n=gi(),m=gi(),memset(f,0x3f3f3f,sizeof(f)); 38 for (RG ll i=1;i<=n;++i) f[i][i]=0; 39 for (RG ll i=1,u,v,w;i<=m;++i) 40 u=gi(),v=gi(),w=gi(),f[u][v]=f[v][u]=w,g[u][v]=g[v][u]=1; 41 for (RG ll k=1;k<=n;++k) 42 for (RG ll i=1;i<=n;++i){ 43 if (i==k) continue; 44 for (RG ll j=1;j<=n;++j){ 45 if (j==i || j==k) continue; 46 if (f[i][j]>f[i][k]+f[k][j]) f[i][j]=f[i][k]+f[k][j],g[i][j]=0; 47 if (f[i][j]==f[i][k]+f[k][j]) g[i][j]+=g[i][k]*g[k][j]; 48 } 49 } 50 for (RG ll k=1;k<=n;++k) 51 for (RG ll i=1;i<=n;++i){ 52 if (i==k) continue; 53 for (RG ll j=1;j<=n;++j){ 54 if (j==i || j==k) continue; 55 if (f[i][j]==f[i][k]+f[k][j]) ans[k]+=g[i][k]*g[k][j]/g[i][j]; 56 } 57 } 58 for (RG ll i=1;i<=n;++i) printf("%0.3lf\n",ans[i]); 59 return 0; 60 }