Find a set of at most N/2 nodes from a Graph such that all remaining nodes are directly connected to one of the chosen nodes

#include
using namespace std;
  

void addEdge(vector& adj,
             int u, int v)
{
    adj[u].push_back(v);
    adj[v].push_back(u);
}
  

vector BFS(
    int N, int source,
    vector adjlist)
{
    
    
    int dist[N + 1];
  
    vector vertex_set;
  
    
    
    memset(dist, -1, sizeof dist);
  
    
    
    vertex_set.assign(2, vector(0));
  
    
    queue Q;
  
    
    Q.push(source);
    dist = 0;
  
    
    while (!Q.empty()) {
  
        
        
        int u = Q.front();
        Q.pop();
  
        
        vertex_set[dist[u] % 2].push_back(u);
  
        
        
        for (int i = 0;
             i < (int)adjlist[u].size(); i++) {                             int v = adjlist[u][i];                             if (dist[v] == -1) {                                     dist[v] = dist[u] + 1;                                     Q.push(v);             }         }     }             return vertex_set; }    void findSet(int N,              vector adjlist) {          int source = 1;             vector vertex_set         = BFS(N, source, adjlist);                  int in = 0;        if (vertex_set[1].size()         < vertex_set[0].size())         in = 1;             for (int node : vertex_set[in]) {         cout