1491: [NOI2007]社交网络
Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1086 Solved: 629
[Submit][Status][Discuss]
Description
![](http://www.lydsy.com/JudgeOnline/images/1491_1.jpg)
Input
![](http://www.lydsy.com/JudgeOnline/images/1491_2.jpg)
Output
输出文件包括n 行,每行一个实数,精确到小数点后3 位。第i 行的实数表 示结点i 在社交网络中的重要程度。
Sample Input
4 4
1 2 1
2 3 1
3 4 1
4 1 1
1 2 1
2 3 1
3 4 1
4 1 1
Sample Output
1.000
1.000
1.000
1.000
1.000
1.000
1.000
HINT
为1
开始是用的整形,强制转换实型结果被精度卡掉了……
n<=100,直接Floyd就好了,开一个数组记录两点间最短路条数(乘法原理)。
#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 ",v[i]); return 0; }