Description
Input
Output
The output file consists of n rows, one real number per line, and 3 digits after the decimal point. The real number on line I indicates how important node I is in social networks.
Sample Input
4 4
1 2 1
2 3 1
3 4 1
4 1 1
Sample Output
1.000
1.000
1.000
1.000
HINT
is 1
Analysis: A look at the scope of laughter, Floyd do not explain.
#include <iostream>#include<cstdio>#include<cstdlib>using namespacestd;Doublemap[101][101];Doublea[101][101];Doubleans[101];intMain () {intn,m; CIN>> N >>m; for(intI=1; i<=n; i++) for(intj=1; j<=n; J + +) Map[i][j]=1e15; for(intI=1; i<=m; i++) { intx, y; DoubleZ; scanf ("%D%D%LF",&x,&y,&z); Map[x][y]=map[y][x]=Z; A[x][y]=a[y][x]=1; } for(intk=1; k<=n; k++) for(intI=1; i<=n; i++) for(intj=1; j<=n; J + +) { if(Map[i][k]+map[k][j]<map[i][j]) {Map[i][j]=map[i][k]+map[k][j]; a[i][j]=0; } if(Map[i][k]+map[k][j]==map[i][j]) a[i][j]+=a[i][k]*A[k][j]; } for(intI=1; i<=n; i++) a[i][i]=0; for(intk=1; k<=n; k++) for(intI=1; i<=n; i++) for(intj=1; j<=n; J + +) if(Map[i][k]+map[k][j]==map[i][j] && a[i][j]>0) ans[k]+=a[i][k]*a[k][j]/A[i][j]; for(intI=1; i<=n; i++) printf ("%.3lf\n", Ans[i]); System ("Pause"); return 0;}
bzoj1491| Social Network | Floyd