home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / misc / LEDA_gene.lha / LEDA-3.1c-generic / prog / graphics / strongcomp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-05  |  913 b   |  68 lines

  1. #include <LEDA/graph_alg.h>
  2. #include <LEDA/graph_edit.h>
  3. #include <LEDA/array.h>
  4.  
  5.  
  6. int STRONG(graph& G, node_array<int>& compnum)
  7.   node v,w;
  8.   int n = G.number_of_nodes();
  9.   int count = 0;
  10.  
  11.   array<node> V(1,n);
  12.   list<node>  S;
  13.  
  14.   node_array<int>  dfs_num(G);
  15.   node_array<int>  compl_num(G);
  16.   node_array<bool> reached(G,false);
  17.  
  18.   DFS_NUM(G,dfs_num,compl_num);
  19.  
  20.   forall_nodes(v,G) V[compl_num[v]] = v;
  21.  
  22.   G.rev();
  23.  
  24.   for(int i = n; i > 0; i--)
  25.    { if ( ! reached[V[i]] ) 
  26.      { S = DFS(G,V[i],reached);
  27.        forall(w,S) compnum[w] = count;
  28.        count++;
  29.       }
  30.     }
  31.  
  32.  return count;
  33.    
  34. }
  35.  
  36.  
  37.  
  38. main()
  39. {
  40.   GRAPH<point,int>  G;
  41.  
  42.   window W;
  43.  
  44.  
  45.   for(;;)
  46.   { 
  47.     graph_edit(W,G);
  48.  
  49.     node_array<int> comp_num(G);
  50.  
  51.     STRONG(G,comp_num);
  52.  
  53.     node v;
  54.     forall_nodes(v,G)
  55.     { int i = comp_num[v];
  56.        W.draw_int_node(G[v],i,i%16);
  57.      }
  58.  
  59.    if (W.read_mouse() == 3) break;
  60.  
  61.   }
  62.  
  63.   return 0;
  64.  
  65. }
  66.  
  67.