fork download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <cstdlib>
  7. #include <vector>
  8. #include <set>
  9. #include <map>
  10. #include <queue>
  11. #include <stack>
  12. #include <list>
  13. #include <cmath>
  14. #include <iomanip>
  15. #define dibs reserve
  16. #define OVER9000 1234567890
  17. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  18. #define tisic 47
  19. #define soclose 1e-6
  20. #define chocolate win
  21. // so much chocolate
  22. #define patkan 9
  23. #define ff first
  24. #define ss second
  25. #define abs(x) ((x < 0)?-(x):x)
  26. #define uint unsigned int
  27. using namespace std;
  28. // mylittledoge
  29.  
  30. typedef long double dbl;
  31.  
  32. struct info {string a,b; int c;};
  33.  
  34. int main() {
  35. cin.sync_with_stdio(0);
  36. cin.tie(0);
  37. int T;
  38. cin >> T;
  39. int t =0;
  40. while(T-- > 0) {
  41. t++;
  42. int M;
  43. string S;
  44. cin >> M >> S;
  45. map<string,int> C;
  46. vector<info> R(M);
  47. for(int i =0; i < M; i++) {
  48. cin >> R[i].a >> R[i].b >> R[i].c;
  49. C[R[i].a] =0;
  50. C[R[i].b] =0;}
  51. int N =0;
  52. ALL_THE(C,it) it->ss =N++;
  53. vector< vector< pair<int,int> > > G(N);
  54. for(int i =0; i < M; i++)
  55. G[C[R[i].a]].push_back(make_pair(C[R[i].b],R[i].c));
  56.  
  57. vector< vector<int> > D(N,vector<int>(N,OVER9000));
  58. vector< vector<dbl> > P(N,vector<dbl>(N,0));
  59. for(int i =0; i < N; i++) {
  60. D[i][i] =0, P[i][i] =1;
  61. priority_queue< pair<int,int>, vector< pair<int,int> > , greater< pair<int,int> > > q;
  62. q.push(make_pair(0,i));
  63. while(!q.empty()) {
  64. pair<int,int> p =q.top();
  65. q.pop();
  66. if(p.ff != D[i][p.ss]) continue;
  67. ALL_THE(G[p.ss],it) {
  68. if(D[i][it->ff] > it->ss+p.ff) {
  69. D[i][it->ff] =it->ss+p.ff;
  70. P[i][it->ff] =P[i][p.ss];
  71. q.push(make_pair(D[i][it->ff],it->ff));}
  72. else if(D[i][it->ff] == it->ss+p.ff) P[i][it->ff] +=P[i][p.ss];}
  73. }
  74. }
  75.  
  76. cout << "Case #" << t << ":";
  77. vector<dbl> ans(M,0);
  78. for(int i =0; i < M; i++) {
  79. int x =0;
  80. for(int j =0; j < N; j++) if(D[C[S]][j] < OVER9000 && j != C[S]) {
  81. x++;
  82. if(D[C[S]][C[R[i].a]]+R[i].c+D[C[R[i].b]][j] == D[C[S]][j])
  83. ans[i] +=P[C[S]][C[R[i].a]]*P[C[R[i].b]][j]/P[C[S]][j];
  84. }
  85. ans[i] /=x;
  86. cout << fixed << setprecision(7) << " " << ans[i];}
  87. cout << "\n";}
  88. return 0;}
  89.  
  90. // look at my code
  91. // my code is amazing
Success #stdin #stdout 0s 3444KB
stdin
Standard input is empty
stdout
Standard output is empty