Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <map>
- using namespace std;
- struct Grafo
- {
- vector <vector <int> > adj;
- map<string, int> mapa;
- int calcularId(string s)
- {
- ///Acá usamos el mapa
- if(mapa[s] == 0)
- mapa[s] = mapa.size();
- return mapa[s];
- }
- void leer()
- {
- int nodos = 80000, aristas;
- cin >> aristas;
- adj.resize(nodos+1);
- string pais1, pais2;
- for(int i=0; i<aristas; i++)
- {
- cin >> pais1 >> pais2;
- int id1 = calcularId(pais1);
- int id2 = calcularId(pais2);
- adj[id1].push_back(id2);
- adj[id2].push_back(id1);
- }
- for(auto i:mapa)
- {
- cout << i.first << " " << i.second << endl;
- }
- }
- };
- int main()
- {
- Grafo g;
- g.leer();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment