Description Solution
N<=100 Natural Association Floyd
Set two arrays d[n][n] minimum distance, t[n][n] minimum number of paths
Update d on the way to update T, multiplication principle
1 if (d[i][j]>d[i][k]+d[k][j]) {2 d[i][j]=d[i][k]+d[k][j]; 3 t[i][j]=t[i][k]*T[k][j]; 4 }5Elseif(d[i][j]==d[i][k]+d[k][j])6 t[i ][J]+=T[I][K]*T[K][J];
The answer to the statistics
1 if (d[i][j]==d[i][k]+d[k][j]) 2 c[k]+= (double) (T[i][k]*t[k][j])/t[i][j];
Feel Floyd can do these things.
Code
1#include <cstdio>2#include <algorithm>3#include <cstring>4 #definell Long Long5 Const intmaxn= the;6 7 ll D[MAXN][MAXN],T[MAXN][MAXN];8 intn,m;9 DoubleC[MAXN];Ten One intMain () { Ascanf"%d%d",&n,&m); - intu,v,w; -memset (D,127/3,sizeof(d)); the for(intI=1; i<=n;i++) -d[i][i]=0, t[i][i]=1; - - for(intI=1; i<=m;i++){ +scanf"%d%d%d",&u,&v,&W); - if(w<D[u][v]) { +d[u][v]=d[v][u]=W; At[u][v]=t[v][u]=1; at } - Else if(w==D[u][v]) { -t[u][v]++; -t[v][u]++; - } - } in - for(intk=1; k<=n;k++) to for(intI=1; i<=n;i++) + for(intj=1; j<=n;j++)if(i!=j&&i!=k&&j!=k) { - if(d[i][j]>d[i][k]+D[k][j]) { thed[i][j]=d[i][k]+D[k][j]; *t[i][j]=t[i][k]*T[k][j]; $ }Panax Notoginseng Else if(d[i][j]==d[i][k]+D[k][j]) -t[i][j]+=t[i][k]*T[k][j]; the } + AMemset (c,0,sizeof(c)); the for(intI=1; i<=n;i++) + for(intj=1; j<=n;j++) - for(intk=1; k<=n;k++)if(i!=j&&i!=k&&j!=k) { $ if(D[i][j]!=d[i][k]+d[k][j])Continue; $c[k]+= (Double) t[i][k]*t[k][j]/T[i][j]; - } - the for(intI=1; i<=n;i++) -printf"%.3lf\n", C[i]);Wuyi return 0; the}
"Floyd" BZOJ1491: [NOI2007] Social network