File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed
Competitive Coding/Graphs/Detecting cycles Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ typedef struct
1111{
1212 ll src;
1313 ll dest;
14- }edge;// This is the structure that saves the source and destination of each edge since it is a directed edge.
14+ }edge;
1515class Graph
1616{
1717private:
@@ -22,21 +22,29 @@ class Graph
2222 vector<ll> rank;
2323 list<ll> *array;
2424public:
25- Graph (ll vertices=0 ,ll edge=0 )// this constructor initialises the list for the vertices.The parent array and their rank.
25+ Graph (ll vertices=0 ,ll edge=0 )
2626 :vertex(vertices),edges(edge)
2727 {
2828 array= new list<ll>[vertex];
2929 parent.assign (vertex,-1 );
3030 rank.assign (vertex,0 );
3131 }
32- ll find (ll v)// This returns the parent of the given vertex
32+ Graph (const Graph &g2)
33+ {
34+ vertex=g2.vertex ;
35+ edges=g2.edges ;
36+ array= new list<ll>[vertex];
37+ parent.assign (vertex,-1 );
38+ rank.assign (vertex,0 );
39+ }
40+ ll find (ll v)
3341 {
3442 if (parent[v]==-1 )
3543 return v;
3644 else
3745 find (parent[v]);
3846 }
39- void unions (ll x,ll y)// This unites two vertex
47+ void unions (ll x,ll y)
4048 {
4149 ll xroot=find (x);
4250 ll yroot=find (y);
@@ -51,7 +59,7 @@ class Graph
5159 rank[yroot]++;
5260 }
5361 }
54- ll iscycle (ll x,ll y)// This tells weather the given edge form a cycle of not
62+ ll iscycle (ll x,ll y)
5563 {
5664
5765 ll xroot=find (x);
You can’t perform that action at this time.
0 commit comments