Check for transitive property in a given Undirected Graph

#include
using namespace std;
  

class Graph {
  
    
    int V;
  
    
    
    list* adj;
  
    
    void DFSUtil(int v, bool visited[], int id[],
                 int id_number, int& c);
  
public:
    Graph(int V);
    ~Graph();
  
    
    void addEdge(int v, int w);
  
    
    
    bool connectedComponents();
};
  
Graph::Graph(int V)
{
    this->V = V;
    adj = new list[V + 1];
}
  

Graph::~Graph() { delete[] adj; }
  

void Graph::addEdge(int v, int w)
{
    adj[v].push_back(w);
    adj[w].push_back(v);
}
  

void Graph::DFSUtil(int v, bool visited[], int id[],
                    int id_number, int& c)
{
  
    
    visited[v] = true;
  
    
    
    id[v] = id_number;
  
    
    
    c++;
  
    
    
    list::iterator i;
  
    
    
    for (i = adj[v].begin(); i != adj[v].end();
         ++i) {
  
        
        if (!visited[*i])
            DFSUtil(*i, visited, id,
                    id_number, c);
    }
}
  

bool Graph::connectedComponents()
{
  
    bool* visited = new bool[V + 1];
  
    
    
    int* id = new int[V + 1];
  
    
    
    int* component_size = new int[V + 1];
  
    
    for (int v = 1; v