2023-01-19 15:36:33 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <vector>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
class Graph
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
//n is the number of vertices
|
|
|
|
//edges is a list of pairs representing the edges (default = empty list)
|
|
|
|
Graph(int n, const list< pair<int, int> > & edges = list< pair<int, int> >());
|
|
|
|
|
|
|
|
//Default constructor creates an empty graph
|
|
|
|
Graph(): n(0), m(0) {};
|
|
|
|
|
|
|
|
//Returns the number of vertices
|
|
|
|
int GetNumVertices() const { return n; };
|
|
|
|
//Returns the number of edges
|
|
|
|
int GetNumEdges() const { return m; };
|
|
|
|
|
|
|
|
//Given the edge's index, returns its endpoints as a pair
|
|
|
|
pair<int, int> GetEdge(int e) const;
|
|
|
|
//Given the endpoints, returns the index
|
|
|
|
int GetEdgeIndex(int u, int v) const;
|
|
|
|
|
|
|
|
//Adds a new vertex to the graph
|
|
|
|
void AddVertex();
|
|
|
|
//Adds a new edge to the graph
|
|
|
|
void AddEdge(int u, int v);
|
|
|
|
|
|
|
|
//Returns the adjacency list of a vertex
|
2023-01-20 23:41:37 +00:00
|
|
|
const vector<int>& AdjList(int v) const;
|
2023-01-19 15:36:33 +00:00
|
|
|
|
|
|
|
//Returns the graph's adjacency matrix
|
|
|
|
const vector< vector<bool> > & AdjMat() const;
|
|
|
|
private:
|
|
|
|
//Number of vertices
|
|
|
|
int n;
|
|
|
|
//Number of edges
|
|
|
|
int m;
|
|
|
|
|
|
|
|
//Adjacency matrix
|
|
|
|
vector< vector<bool> > adjMat;
|
|
|
|
|
|
|
|
//Adjacency lists
|
2023-01-20 23:41:37 +00:00
|
|
|
vector<vector<int> > adjList;
|
2023-01-19 15:36:33 +00:00
|
|
|
|
|
|
|
//Array of edges
|
2023-01-20 23:41:37 +00:00
|
|
|
vector<pair<int, int> > edges;
|
2023-01-19 15:36:33 +00:00
|
|
|
|
|
|
|
//Indices of the edges
|
2023-01-20 23:41:37 +00:00
|
|
|
vector<vector<int> > edgeIndex;
|
2023-01-19 15:36:33 +00:00
|
|
|
};
|