SHARE
TWEET

Untitled

a guest Feb 27th, 2020 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. # define NMAX 50000
  3. using namespace std;
  4.  
  5. int n,s=0,minn=5000,k=0, a[105][105];
  6.  
  7. void Read()
  8. {
  9.     ifstream fin("date.in");
  10.     ofstream fout("date.out");
  11.  
  12.     int i, j;
  13.     fin >> n;
  14.  
  15.     for (i = 1; i <= n; i++)
  16.         for (j = 1; j <= n; j++)
  17.             fin >> a[i][j];
  18.  
  19. }
  20.  
  21. void Roy_Floyd()
  22. {
  23.     int i, j, k;
  24.     for (k = 1; k <= n; k++)
  25.         for (i = 1; i <= n; i++)
  26.             for (j = 1; j <= n; j++)
  27.                 if (a[i][j] > a[i][k] + a[k][j])
  28.                     a[i][j] = a[i][k] + a[k][j];
  29. }
  30. void drum(int i,int j)
  31. {
  32.     int k,gasit;
  33.     for(k=1,gasit=0;k<=n && !gasit;k++)
  34.     if(i!=k && j!=k && a[i][j]==a[i][k]+a[k][j])
  35.     {
  36.         drum(i,k);
  37.         drum(k,j);
  38.         gasit=1;
  39.         }
  40.      if(!gasit)
  41.      cout<<j<<" ";
  42. }
  43.  
  44.  
  45. void Write()
  46. {
  47.     int i, j;
  48.     for (i = 1; i <= n; i++)
  49.     {
  50.         for (j = 1; j <= n; j++)
  51.         cout << a[i][j]<<" ";
  52.         cout << endl;
  53.     }
  54. }
  55.  
  56. void Minim()
  57. {
  58.  
  59.     for(int i=1;i<=n;i++)
  60.      {
  61.       int s=0;
  62.       for(int j=1;j<=n;j++)
  63.       {
  64.           s+=a[i][j];
  65.       }
  66.       a[0][i]=s;
  67.       if(minn>a[0][i])
  68.       {
  69.           minn=a[0][i];
  70.             k=i;}
  71.      }
  72.     cout<<k;
  73. }
  74.  
  75.  
  76. int main()
  77. {
  78.     Read();
  79.     Roy_Floyd();
  80.     Write();
  81.     Minim();
  82.     return 0;
  83. }
  84.  
  85. 5
  86. 0 5 5000 3 5000
  87. 2 0 1 10 16
  88. 10 5000 0 5000 7
  89. 5000 5000 5000 0 3
  90. 5000 1 14 5000 0
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top