Graph::cutVertex

Function


vector<vertex<T> > cutVertex();

Get the cut vertices of the graph. A cut vertex is any vertex that when removed increases the number of connected components.

Parameters

None

Return value

Return a vector of vertices which contains all cut vertices.

Example

#include "HKUAL_graph.h"
#include <iostream>
#include <vector>
using namespace std;
using namespace HKUAL;

int main(){
    Graph<string> g;
    g.addVertex("A");
    g.addVertex("B");
    g.addVertex("C");
    g.addVertex("D");
    g.addVertex("E");
    g.addVertex("F");
	
    g.addEdge("A","D");
    g.addEdge("A","E");
    g.addEdge("B","D");
    g.addEdge("C","D");
    g.addEdge("C","E");
    vector<Vertex<string> > v = g.cutVertex();
    for (int i = 0; i < v.size(); i++)
       cout << v[i].label << endl;
    return 0;
}

Output

D

Time Complexity

, for is number of edges and is total number of vertices.

© The University of Hong Kong Algorithms Library - hkual@cs.hku.hk