Guest User

INOI1402

a guest
Jul 4th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int c,f,x,y,p;
  7.     cin>>c>>f;
  8.  
  9.  
  10.     int graph[231][231],dist[231][231];
  11.     for(int i=0;i<c;i++)
  12.     {
  13.         for(int j=0;j<c;j++)
  14.         {
  15.             if (i==j)
  16.                 graph[i][j]=0;
  17.             else
  18.                 graph[i][j]=INT_MAX;
  19.         }
  20.     }
  21.     for(int i=1;i<=f;i++)
  22.     {
  23.         cin>>x>>y>>p;
  24.         graph[x][y]=p;
  25.         graph[y][x]=p;
  26.     }
  27.  
  28.     for(int i=0;i<c;i++)
  29.     {
  30.         for(int j=0;j<c;j++)
  31.             dist[i][j]=graph[i][j];
  32.     }
  33.  
  34.     for (int k=0;k<c;k++)
  35.     {
  36.         for(int i=0;i<c;i++)
  37.         {
  38.             for (int j=0;j<c;j++)
  39.             {
  40.                 if (dist[i][j] > dist[i][k] + dist[k][j])
  41.                     dist[i][j] = dist[i][k] + dist[k][j];
  42.             }
  43.         }
  44.     }
  45.  
  46.  
  47.     int max=0;
  48.     for(int i=0;i<c;i++)
  49.     {
  50.         for(int j=0;j<c;j++)
  51.             if (max<dist[i][j]) max=dist[i][j];
  52.     }
  53.  
  54.     cout <<max;
  55.  
  56.  
  57.  
  58.  
  59.  
  60. }
Add Comment
Please, Sign In to add comment