Advertisement
saske_7

warshall_uva821.cpp

Nov 13th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std ;
  4.  
  5. #define M 999999999
  6. #define pii pair<int , int >
  7. #define mp make_pair
  8. #define pf printf
  9. #define sf scanf
  10. #define sf1(a ) scanf("%d",&a)
  11. #define pb push_back
  12. #define sf2(a, b) scanf("%d%d",&a ,&b)
  13. #define rep(i,n ) for(i = 0 ; i< n ;i++ )
  14.  
  15. typedef long long LL ;
  16.  
  17. void warshall(LL arr[][200] ,LL num){
  18.     LL i , j , k ;
  19.     for(k =1 ; k <= num ;k++){
  20.         for(i = 1 ;i<= num ;i++ ){
  21.             for(j =  1;j<= num ; j++)
  22.             {
  23.                 if(arr[i][k] + arr[k][j] <= arr[i][j]){
  24.                     arr[i][j] = arr[i][k] + arr[k][j] ;
  25.                 }
  26.  
  27.             }
  28.     }
  29. }
  30.  
  31. return ;
  32. }
  33.  
  34. int main(){
  35.    // freopen("in.txt","r",stdin);
  36.    // freopen("out.txt","w",stdout);
  37.  
  38. LL tc , i ,j , k;
  39. LL arr[200][200] , _time[200][200], p=0;
  40.  
  41. LL a , b ,count = 1;
  42. int cs = 0;
  43. map<int , int >m ;
  44. while(scanf("%lld%lld",&a , &b )){
  45.     if( a == 0 && b == 0 ) break ;
  46.     m.clear();
  47.     for(i = 1 ;i<= 100 ;i++ ){
  48.         for(j =  1;j<= 100 ; j++){
  49.             arr[i][j] = M;
  50.         }
  51.         }
  52.     for(i = 1 ;i<= 100 ;i++ ){
  53.             arr[i][i] = 0;
  54.         }
  55.     m[a] = count++;
  56.     m[b] =  count++;
  57.  
  58.     arr[a][b] =  1;
  59.  
  60.     while(scanf("%lld%lld",&a , &b )){
  61.     if( a == 0 && b == 0 ) break ;
  62.         if(m.find(a) == m.end() )m[a] =  count++ ;
  63.         if(m.find(b) == m.end() )m[b] =  count++ ;
  64.  
  65.         arr[m[a] ][m[b]] =  1 ;
  66.  
  67.  
  68.     }
  69.  
  70.     count-- ;
  71.     warshall(arr , count);
  72.     LL sum = 0 ;
  73.     double ret ;
  74.     LL num = count;
  75.  
  76.     for(i = 1 ;i<= num ;i++ ){
  77.         for(j =  1;j<= num ; j++){
  78.             sum += arr[i][j];
  79.  
  80.         }
  81.     }
  82.     count =  count*count  - count;
  83.  
  84.     ret =(double) sum/count ;
  85.  
  86.     pf("Case %d: average length between pages = %.3lf clicks\n", ++cs , ret);
  87. //    pf("%lld %lld\n",sum  , count );
  88. count =  1;
  89. }
  90.  
  91.     return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement