/* ** This is a C++ implementation of John Edward Hopcroft & ** Robert Endre Tarjan's algorithm for finding articulation vertices ** and edges of a connected undirected graph. As this is a variant of ** DFS, the runtime complexity is O(V+E) */ #include <cstdio> #include <vector> using namespace std; #define MAX 100 #define min(a,b) ((a)<(b)?(a):(b)) #define INF 2147483647 vector<int> adjList[MAX+7]; int V, iterCount,rootChildren,dfs_root,dfs_low[MAX+7],dfs_num[MAX+7],dfs_parent[MAX+7]; bool artiVertex[MAX+7],artiEdge[MAX+7][MAX+7]; void process(int u) { dfs_num[u]=dfs_low[u]=iterCount++; int v; for(int i=0;i<(int)adjList[u].size();i++) { v=adjList[u][i]; if(dfs_num[v]==INF) { if(u==dfs_root) rootChildren++; dfs_parent[v]=u, process(v); if(dfs_low[v]>=dfs_num[u]) { artiVertex[u]=true; if(dfs_low[v]>dfs_num[u]) artiEdge[u][v]=artiEdge[v][u]=true; } dfs_low[u]=min(dfs_low[u],dfs_low[v]); } else if(v!=dfs_parent[u]) dfs_low[u]=min(dfs_low[u],dfs_num[v]); } } int main() { /* dfs_low[]=INF, dfs_num[]=INF, iterCount=0, rootChildren=0; process(dfs_root), artiVertex[dfs_root]=(rootChildren>1); */ return 0; }
ArticulationCheck
Subscribe to:
Posts (Atom)