/*
 * "This code is from "Algorithms in C, Third Edition,"
 * by Robert Sedgewick, Addison-Wesley, 2002."
 * (Small edits by Y. Kohayakawa)
 */ 

#include "prog17.3.c"

#define maxV 10000
static int cnt, pre[maxV];

/* prog18.1 */

#define dfsR search
void dfsR(Graph G, Edge e)
  { int t, w = e.w;
    pre[w] = cnt++; 
    for (t = 0; t < G->V; t++)
      if (G->adj[w][t] != 0) 
        if (pre[t] == -1)
          dfsR(G, EDGE(w, t)); 
  }

/* prog18.3 */

void GRAPHsearch(Graph G)
  { int v;
    cnt = 0;
    for (v = 0; v < G->V; v++) pre[v] = -1;
    for (v = 0; v < G->V; v++)
      if (pre[v] == -1) 
        search(G, EDGE(v, v));
  }

void GRAPHshow_pre(Graph G)
{
  int v;
  printf("pre[]: ");
  for (v = 0; v < G->V; v++)
    printf("%d ", pre[v]);
  putchar('\n');
}
