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

#include "prog17.6.c"

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

/* prog18.2 */

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

/* 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');
}
