GastonFontenla

Untitled

Jul 3rd, 2017
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. #define INF (1 << 29)
  5.  
  6. using namespace std;
  7.  
  8. struct Arista
  9. {
  10.     int hacia, costo;
  11. };
  12.  
  13. Arista armarArista(int hacia, int costo)
  14. {
  15.     Arista ar;
  16.     ar.hacia = hacia;
  17.     ar.costo = costo;
  18.     return ar;
  19. }
  20.  
  21. struct Grafo
  22. {
  23.     vector <vector <Arista> > adj;
  24.     vector <vector <int> > m;
  25.     int nodos, aristas;
  26.     void leer()
  27.     {
  28.         cin >> nodos >> aristas;
  29.         adj.resize(nodos+1);
  30.         m = vector <vector <int> > (nodos+1, vector <int> (nodos+1, INF));
  31.  
  32.         int desde, hacia, costo;
  33.  
  34.         for(int i=0; i<aristas; i++)
  35.         {
  36.             cin >> desde >> hacia >> costo;
  37.             adj[desde].push_back(armarArista(hacia, costo));
  38.             adj[hacia].push_back(armarArista(desde, costo));
  39.             m[desde][hacia] = costo;
  40.             m[hacia][desde] = costo;
  41.         }
  42.     }
  43.  
  44.     void floydWarshall() ///MAGIA
  45.     {
  46.         for(int k=1; k<=nodos; k++)
  47.             for(int i=1; i<=nodos; i++)
  48.                 for(int j=1; j<=nodos; j++)
  49.                     m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
  50.     }
  51. };
  52.  
  53. int main()
  54. {
  55.     cout << "Hello world!" << endl;
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment