记录编号 115711 评测结果 AAAAAAAAAA
题目名称 [NOI 2007]社交网络 最终得分 100
用户昵称 GravatarHouJikan 是否通过 通过
代码语言 C++ 运行时间 0.047 s
提交时间 2014-08-22 11:08:49 内存使用 0.47 MiB
显示代码纯文本
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdio>
  4. #include <cstdlib>
  5. #include <cmath>
  6. #include <algorithm>
  7. #include <queue>
  8. #include <stack>
  9. #include <map>
  10. #include <set>
  11. #include <list>
  12. #include <vector>
  13. #include <ctime>
  14. #include <iterator>
  15. #include <functional>
  16. #define pritnf printf
  17. #define scafn scanf
  18. #define For(i,j,k) for(int i=(j);i<=(k);(i)++)
  19. using namespace std;
  20. typedef long long LL;
  21. typedef unsigned int Uint;
  22. const int INF=10000000;
  23. //==============struct declaration==============
  24.  
  25. //==============var declaration=================
  26. LL dist[101][101];
  27. LL way[101][101];
  28. //==============function declaration============
  29.  
  30. //==============main code=======================
  31. int main()
  32. {
  33. string FileName="network1";//程序名
  34. string FloderName="COGS";//文件夹名
  35. freopen((FileName+".in").c_str(),"r",stdin);
  36. freopen((FileName+".out").c_str(),"w",stdout);
  37. #ifdef DEBUG
  38. system(("cp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\standard.cpp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\submit.txt").c_str());
  39. #endif
  40. int n,m;
  41. int s,e,w;
  42. scanf("%d%d",&n,&m);
  43. For(i,1,n)
  44. {
  45. For(j,1,n)
  46. {
  47. dist[i][j]=INF;
  48. way[i][j]=1;
  49. }
  50. dist[i][i]=INF;
  51. }
  52. For(i,1,m)
  53. {
  54. scanf("%d%d%d",&s,&e,&w);
  55. dist[s][e]=dist[e][s]=w;
  56. }
  57. For(k,1,n)
  58. For(i,1,n)
  59. For(j,1,n)
  60. {
  61. if (i==j||i==k||j==k) continue;
  62. if (dist[i][k]+dist[k][j]<dist[i][j])
  63. {
  64. dist[i][j]=dist[i][k]+dist[k][j];
  65. way[i][j]=way[i][k]*way[k][j];
  66. }
  67. else if (dist[i][k]+dist[k][j]==dist[i][j])
  68. way[i][j]+=way[i][k]*way[k][j];
  69. }
  70. /*
  71. For(i,1,n)
  72. For(j,1,n)
  73. printf("%d-->%d minway->%d\n",i,j,way[i][j]);
  74. */
  75. For(v,1,n)
  76. {
  77. double I=0;
  78. For(s,1,n)
  79. For(e,1,n)
  80. if (dist[s][v]+dist[v][e]==dist[s][e])
  81. I+=double(way[s][v]*way[v][e])/way[s][e];
  82. printf("%.3lf\n",I);
  83. }
  84. return 0;
  85. }
  86. //================fuction code====================