Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <deque>
- #include <algorithm>
- using namespace std;
- int main( ) {
- int n, m; // n vertices, m aristas
- cin >> n >> m;
- vector<int> adyacencia[n];
- for (int i = 0; i < m; ++i) {
- char x, y;
- cin >> x >> y;
- adyacencia[x - 'A'].push_back(y - 'A');
- adyacencia[y - 'A'].push_back(x - 'A');
- }
- deque<int> cola = { 0 };
- bool impresos[n]; fill_n(&impresos[0], n, false);
- do{
- int procesar=cola.front();
- cola.pop_front();
- if(impresos[procesar]==false)
- {
- cout<< char(procesar + 'A')<<" ";
- impresos[procesar]= true;
- for(int vecino: adyacencia[procesar])
- {
- cola.push_back(vecino);
- }
- }
- }while(!cola.empty());
- }
Advertisement
Add Comment
Please, Sign In to add comment