home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************************
- +
- + LEDA 2.1.1 11-15-1991
- +
- +
- + _bicomp.c
- +
- +
- + Copyright (c) 1991 by Max-Planck-Institut fuer Informatik
- + Im Stadtwald, 6600 Saarbruecken, FRG
- + All rights reserved.
- +
- *******************************************************************************/
-
-
-
- /*******************************************************************************
- * *
- * BICONNECTED COMPONENTS *
- * *
- *******************************************************************************/
-
-
-
- #include <LEDA/graph_alg.h>
-
- declare(node_array,node)
-
- void bcc_dfs(const ugraph& G, node v, node_array(int)&,
- node_array(int)&,
- node_array(int)&,
- node_array(node)&,
- list(node)&,
- int&,
- int&);
-
-
- int BICONNECTED_COMPONENTS(const ugraph& G, node_array(int)& compnum)
- {
- // computes the biconnected components of undirected graph G
- // returns m = number of biconnected components
- // returns in edge_array(int) compnum for each edge an integer with
- // compnum[x] = compnum[y] iff x and y belong to the same component
- // 0 <= compnum[e] <= m-1 for all edges e
-
- list(node) unfinished;
- node_array(int) dfsnum(G,-1);
- node_array(int) lowpt(G);
- node_array(node) father(G);
-
- int count1 = 0;
- int count2 = 0;
-
- node v;
-
- forall_nodes(v,G)
- if (dfsnum[v] == (-1))
- bcc_dfs(G,v,compnum,dfsnum,lowpt,father,unfinished,count1,count2);
-
- return count2;
- }
-
-
-
- void bcc_dfs(const ugraph& G, node v, node_array(int)& compnum,
- node_array(int)& dfsnum,
- node_array(int)& lowpt,
- node_array(node)& father,
- list(node)& unfinished,
- int& count1, int& count2)
- {
- node w;
-
- dfsnum[v] = ++count1;
-
- lowpt[v] = dfsnum[v];
-
- unfinished.push(v);
-
- forall_adj_nodes(w,v)
- if (dfsnum[w]==-1)
- { father[w] = v;
- bcc_dfs(G,w,compnum,dfsnum,lowpt,father,unfinished,count1,count2);
- lowpt[v] = Min(lowpt[v],lowpt[w]);
- }
- else lowpt[v] = Min(lowpt[v],dfsnum[w]);
-
-
- if ((dfsnum[v] >= 2) && (lowpt[v] == dfsnum[father[v]]))
- { do { w = unfinished.pop();
- compnum[w] = count2;
- } while (v!=w);
-
- count2++;
- }
-
- }
-
-