Generate an array from given pairs of adjacent elements

#include
using namespace std;
  

void find_original_array(vector& A)
{
  
    
    unordered_map mp;
  
    
    vector res;
  
    
    unordered_map visited;
  
    
    
    for (auto& it : A) {
  
        mp[it.first].push_back(it.second);
        mp[it.second].push_back(it.first);
    }
  
    auto it = mp.begin();
  
    
    for (; it != mp.end(); it++) {
        if (it->second.size() == 1) {
            break;
        }
    }
  
    
    
    int adjacent = it->first;
  
    
    res.push_back(it->first);
  
    
    visited[it->first] = true;
  
    
    
    while (res.size() != A.size() + 1) {
  
        
        for (auto& elements : mp[adjacent]) {
  
            
            if (!visited[elements]) {
  
                
                res.push_back(elements);
  
                
                visited[elements] = true;
  
                
                adjacent = elements;
            }
        }
    }
  
    
    for (auto it : res) {
        cout