GastonFontenla

Untitled

May 29th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4.  
  5. using namespace std;
  6.  
  7. struct Grafo
  8. {
  9.     vector <vector <int> > adj;
  10.     map<string, int> mapa;
  11.  
  12.     int calcularId(string s)
  13.     {
  14.         ///Acá usamos el mapa
  15.  
  16.         if(mapa[s] == 0)
  17.             mapa[s] = mapa.size();
  18.         return mapa[s];
  19.     }
  20.  
  21.     void leer()
  22.     {
  23.         int nodos = 80000, aristas;
  24.         cin >> aristas;
  25.  
  26.         adj.resize(nodos+1);
  27.  
  28.         string pais1, pais2;
  29.  
  30.         for(int i=0; i<aristas; i++)
  31.         {
  32.             cin >> pais1 >> pais2;
  33.  
  34.             int id1 = calcularId(pais1);
  35.             int id2 = calcularId(pais2);
  36.  
  37.             adj[id1].push_back(id2);
  38.             adj[id2].push_back(id1);
  39.         }
  40.  
  41.         for(auto i:mapa)
  42.         {
  43.             cout << i.first << " " << i.second << endl;
  44.         }
  45.     }
  46. };
  47.  
  48. int main()
  49. {
  50.     Grafo g;
  51.     g.leer();
  52.  
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment