\input cwebmac
% This file is part of the Stanford GraphBase (c) Stanford University 1993
% This material goes at the beginning of all Stanford GraphBase CWEB files

\def\topofcontents{
  \leftline{\sc\today\ at \hours}\bigskip\bigskip
  \centerline{\titlefont\title}}

\font\ninett=cmtt9
\def\botofcontents{\vskip 0pt plus 1filll
    \ninerm\baselineskip10pt
    \noindent\copyright\ 1993 Stanford University
    \bigskip\noindent
    This file may be freely copied and distributed, provided that
    no changes whatsoever are made. All users are asked to help keep
    the Stanford GraphBase files consistent and ``uncorrupted,''
    identical everywhere in the world. Changes are permissible only
    if the modified file is given a new name, different from the names of
    existing files in the Stanford GraphBase, and only if the modified file is
    clearly identified as not being part of that GraphBase.
    (The {\ninett CWEB} system has a ``change file'' facility by
    which users can easily make minor alterations without modifying
    the master source files in any way. Everybody is supposed to use
    change files instead of changing the files.)
    The author has tried his best to produce correct and useful programs,
    in order to help promote computer science research,
    but no warranty of any kind should be assumed.
    \smallskip\noindent
    Preliminary work on the Stanford GraphBase project
    was supported in part by National Science
    Foundation grant CCR-86-10181.}

\def\prerequisite#1{\def\startsection{\noindent
    Important: Before reading {\sc\title},
    please read or at least skim the program for {\sc#1}.\bigskip
    \let\startsection=\stsec\stsec}}
\def\prerequisites#1#2{\def\startsection{\noindent
    Important: Before reading {\sc\title}, please read
    or at least skim the programs for {\sc#1} and {\sc#2}.\bigskip
    \let\startsection=\stsec\stsec}}



\def\title{ROGET\_\,COMPONENTS}
\def\<#1>{$\langle${\rm#1}$\rangle$}

\prerequisite{GB\_\,ROGET}

\N{1}{1}Strong components. This demonstration program computes the
strong components of GraphBase graphs derived from Roget's Thesaurus,
using a variant of Tarjan's algorithm [R. E. Tarjan, ``Depth-first
search and linear graph algorithms,'' {\sl SIAM Journal on Computing\/
\bf1} (1972), 146--160]. We also determine the relationships
between strong components.

Two vertices belong to the same strong component if and only if they
are reachable from each other via directed paths.

We will print the strong components in ``reverse topological order'';
that is, if \|v is reachable from~\|u but \|u is not reachable
from~\|v, the strong component containing~\|v will be listed before
the strong component containing~\|u.

Vertices from the \\{roget} graph are identified both by name and by
category number.

\Y\B\4\D$\\{specs}(\|v)$ \5
$(\\{filename}\?\|v-\|g\MG\\{vertices}+\T{1\$L}:\|v\MG\\{cat\_no}),\39\|v\MG{}$%
\\{name}\C{ category number and category name }\par
\fi

\M{2}We permit command-line options in \UNIX/ style so that a variety of
graphs can be studied:
The user can say `\.{-n}\<number>', `\.{-d}\<number>', `\.{-p}\<number>',
and/or `\.{-s}\<number>' to change the default values of the parameters
in the graph $\\{roget}(\|n,\|d,\|p,\|s)$. Or `\.{-g}\<filename>' to change the
graph itself.

\Y\B\8\#\&{include} \.{"gb\_graph.h"}\C{ the GraphBase data structures }\6
\8\#\&{include} \.{"gb\_roget.h"}\C{ the \\{roget} routine }\6
\8\#\&{include} \.{"gb\_save.h"}\C{ \\{restore\_graph} }\6
\ATH\7
\X5:Global variables\X\7
${}\\{main}(\\{argc},\39\\{argv}){}$\1\1\6
\&{int} \\{argc};\C{ the number of command-line arguments }\6
\&{char} ${}{*}\\{argv}[\,]{}$;\C{ an array of strings containing those
arguments }\2\2\6
${}\{{}$\5
\1\&{Graph} ${}{*}\|g{}$;\C{ the graph we will work on }\6
\&{register} \&{Vertex} ${}{*}\|v{}$;\C{ the current vertex of interest }\6
\&{unsigned} \&{long} \|n${}\K\T{0}{}$;\C{ the desired number of vertices (0
means infinity) }\6
\&{unsigned} \&{long} \|d${}\K\T{0}{}$;\C{ the minimum distance between
categories in arcs }\6
\&{unsigned} \&{long} \|p${}\K\T{0}{}$;\C{ 65536 times the probability of
rejecting an arc }\6
\&{long} \|s${}\K\T{0}{}$;\C{ the random number seed }\6
\&{char} ${}{*}\\{filename}\K\NULL{}$;\C{ external graph substituted for %
\\{roget} }\7
\X3:Scan the command-line options\X;\6
${}\|g\K(\\{filename}\?\\{restore\_graph}(\\{filename}):\\{roget}(\|n,\39\|d,%
\39\|p,\39\|s));{}$\6
\&{if} ${}(\|g\E\NULL){}$\5
${}\{{}$\1\6
${}\\{fprintf}(\\{stderr},\39\.{"Sorry,\ can't\ create}\)\.{\ the\ graph!\
(error\ c}\)\.{ode\ \%ld)\\n"},\39\\{panic\_code});{}$\6
\&{return} ${}{-}\T{1};{}$\6
\4${}\}{}$\2\6
${}\\{printf}(\.{"Reachability\ analys}\)\.{is\ of\ \%s\\n\\n"},\39\|g\MG%
\\{id});{}$\6
\X10:Perform Tarjan's algorithm on \|g\X;\6
\&{return} \T{0};\C{ normal exit }\6
\4${}\}{}$\2\par
\fi

\M{3}\B\X3:Scan the command-line options\X${}\E{}$\6
\&{while} ${}(\MM\\{argc}){}$\5
${}\{{}$\1\6
\&{if} ${}(\\{sscanf}(\\{argv}[\\{argc}],\39\.{"-n\%lu"},\39{\AND}\|n)\E%
\T{1}){}$\1\5
;\2\6
\&{else} \&{if} ${}(\\{sscanf}(\\{argv}[\\{argc}],\39\.{"-d\%lu"},\39{\AND}\|d)%
\E\T{1}){}$\1\5
;\2\6
\&{else} \&{if} ${}(\\{sscanf}(\\{argv}[\\{argc}],\39\.{"-p\%lu"},\39{\AND}\|p)%
\E\T{1}){}$\1\5
;\2\6
\&{else} \&{if} ${}(\\{sscanf}(\\{argv}[\\{argc}],\39\.{"-s\%ld"},\39{\AND}\|s)%
\E\T{1}){}$\1\5
;\2\6
\&{else} \&{if} ${}(\\{strncmp}(\\{argv}[\\{argc}],\39\.{"-g"},\39\T{2})\E%
\T{0}){}$\1\5
${}\\{filename}\K\\{argv}[\\{argc}]+\T{2};{}$\2\6
\&{else}\5
${}\{{}$\1\6
${}\\{fprintf}(\\{stderr},\39\.{"Usage:\ \%s\ [-nN][-dN}\)\.{][-pN][-sN][-gfoo]%
\\n}\)\.{"},\39\\{argv}[\T{0}]);{}$\6
\&{return} ${}{-}\T{2};{}$\6
\4${}\}{}$\2\6
\4${}\}{}$\2\par
\U2.\fi

\M{4}Tarjan's algorithm is inherently recursive. We will implement
the recursion explicitly via linked lists, instead of using \CEE/'s runtime
stack, because some computer systems
bog down in the presence of deeply nested recursion.

Each vertex goes through three stages during the algorithm: First it is
``unseen''; then it is ``active''; finally it becomes ``settled,'' when it
has been assigned to a strong component.

The data structures that represent the current state of the algorithm
are implemented by using five of the utility fields in each vertex:
\\{rank}, \\{parent}, \\{untagged}, \\{link}, and \\{min}. We will consider
each of
these in turn.

\fi

\M{5}First is the integer \\{rank} field, which is zero when a vertex is
unseen.
As soon as the vertex is first examined, it becomes active and its \\{rank}
becomes and remains nonzero. Indeed, the $k$th vertex to become active
will receive rank~$k$. When a vertex finally becomes settled, its rank
is reset to infinity.

It's convenient to think of Tarjan's algorithm as a simple adventure
game in which we want to explore all the rooms of a cave. Passageways between
the rooms allow one-way travel only. When we come
into a room for the first time, we assign a new number to that room;
this is its rank. Later on we might happen to enter the same room
again, and we will notice that it has nonzero rank. Then we'll be able
to make a quick exit, saying ``we've already been here.'' (The extra
complexities of computer games, like dragons that might need to be
vanquished, do not arise.)

\Y\B\4\D$\\{rank}$ \5
$\|z.{}$\|I\C{ the \\{rank} of a vertex is stored in utility field \|z }\par
\Y\B\4\X5:Global variables\X${}\E{}$\6
\&{long} \\{nn};\C{ the number of vertices that have been seen }\par
\As8\ET11.
\U2.\fi

\M{6}The active vertices will always form an oriented tree, whose arcs are
a subset of the arcs in the original graph. A tree arc from \|u to~\|v
will be represented by $\|v\MG\\{parent}\E\|u$. Every active vertex has a
parent, which is usually another active vertex; the only exception is
the root of the tree, whose \\{parent} is $\NULL$.

In the cave analogy, the ``parent'' of room \|v is the room we were in
immediately before entering \|v the first time. By following parent
pointers, we will be able to leave the cave whenever we want.

As soon as a vertex becomes settled, its \\{parent} field changes
significance.  Then $\|v\MG\\{parent}$ is set equal to the unique
representative of the strong component containing vertex~\|v. Thus
two settled vertices will belong to the same strong component if and only
if they have the same \\{parent}.

\Y\B\4\D$\\{parent}$ \5
$\|y.{}$\|V\C{ the \\{parent} of a vertex is stored in utility field \|y }\par
\fi

\M{7}All arcs in the original directed graph are explored systematically during
a depth-first search. Whenever we look at an arc, we tag it so that
we won't need to explore it again. In a cave, for example, we might
mark each passageway between rooms once we've tried to go through it.

The algorithm doesn't actually place a tag on its \&{Arc} records; instead,
each vertex \|v has a pointer $\|v\MG\\{untagged}$ that leads to all
hitherto-unexplored arcs from~\|v. The arcs of the list that appear
between $\|v\MG\\{arcs}$ and $\|v\MG\\{untagged}$ are the ones already
examined.

\Y\B\4\D$\\{untagged}$ \5
$\|x.{}$\|A\C{ the \\{untagged} field points to an \&{Arc} record, or $\NULL$ }%
\par
\fi

\M{8}The algorithm maintains two special stacks: \\{active\_stack} contains
all the currently active vertices, and \\{settled\_stack} contains all the
currently settled vertices. Each vertex has a \\{link} field that points
to the vertex that is next lower on its stack, or to $\NULL$ if the vertex is
at the bottom. The vertices on \\{active\_stack} always appear in increasing
order of rank from bottom to top.

\Y\B\4\D$\\{link}$ \5
$\|w.{}$\|V\C{ the \\{link} field of a vertex occupies utility field \|w }\par
\Y\B\4\X5:Global variables\X${}\mathrel+\E{}$\6
\&{Vertex} ${}{*}\\{active\_stack}{}$;\C{ the top of the stack of active
vertices }\6
\&{Vertex} ${}{*}\\{settled\_stack}{}$;\C{ the top of the stack of settled
vertices }\par
\fi

\M{9}Finally there's a \\{min} field, which is the tricky part that makes
everything work. If vertex~\|v is unseen or settled, its \\{min} field is
irrelevant. Otherwise $\|v\MG\\{min}$ points to the active vertex~\|u
of smallest rank having the following property:
Either $\|u\E\|v$ or there is a directed path from \|v to \|u consisting of
zero or more mature tree arcs followed by a single non-tree arc.

What is a tree arc, you ask. And what is a mature arc? Good questions. At the
moment when arcs of the graph are tagged, we classify them either as tree
arcs (if they correspond to a new \\{parent} link in the tree of active
nodes) or non-tree arcs (otherwise). A tree arc becomes mature when it
is no longer on the path from the root to the current vertex being
explored. We also say that a vertex becomes mature when it is
no longer on that path. All arcs from a mature vertex have been tagged.

We said before that every vertex is initially unseen, then active, and
finally settled. With our new definitions, we see further that every arc starts
out untagged, then it becomes either a non-tree arc or a tree arc. In the
latter case, the arc begins as an immature tree arc and eventually matures.

Just believe these definitions, for now. All will become clear soon.

\Y\B\4\D$\\{min}$ \5
$\|v.{}$\|V\C{ the \\{min} field of a vertex occupies utility field \|v }\par
\fi

\M{10}Depth-first search explores a graph by systematically visiting all
vertices and seeing what they can lead to. In Tarjan's algorithm, as
we have said, the active vertices form an oriented tree. One of these
vertices is called the current vertex.

If the current vertex still has an arc that hasn't been tagged, we
tag one such arc and there are two cases: Either the arc leads to
an unseen vertex, or it doesn't. If it does, the arc becomes a tree
arc; the previously unseen vertex becomes active, and it becomes the
new current vertex.  On the other hand if the arc leads to a vertex
that has already been seen, the arc becomes a non-tree arc and the
current vertex doesn't change.

Finally there will come a time when the current vertex~\|v has no
untagged arcs. At this point, the
algorithm might decide that \|v and all its descendants form a strong
component. Indeed, this condition turns out to be true if and only if
$\|v\MG\\{min}\E\|v$; a proof appears below. If so, \|v and all its descendants
become settled, and they leave the tree. If not, the tree arc from
\|v's parent~\|u to~\|v becomes mature, so the value of $\|v\MG\\{min}$ is
used to update the value of $\|u\MG\\{min}$. In both cases, \|v becomes mature
and the new current vertex will be the parent of~\|v. Notice that only the
value of $\|u\MG\\{min}$ needs to be updated, when the arc from \|u to~\|v
matures; all other values $\|w\MG\\{min}$ stay the same, because a newly
mature arc has no mature predecessors.

The cave analogy helps to clarify the situation: If there's no way out
of the subcave starting at~\|v unless we come back through \|v itself,
and if we can get back to \|v from all its descendants, then
room~\|v and its descendants will become a strong component. Once
such a strong component is identified, we close it off and don't
explore that subcave any further.

If \|v is the root of the tree, it always has $\|v\MG\\{min}\E\|v$,
so it will always define a new strong component at the moment it matures.
Then the depth-first search will terminate, since \|v~has no parent.
But Tarjan's algorithm will press on, trying to find a vertex~\|u that is still
unseen. If such a vertex exists,
a new depth-first search will begin with \|u as the root. This
process keeps on going until at last all vertices are happily settled.

The beauty of this algorithm is that it all works very efficiently
when we organize it as follows:

\Y\B\4\X10:Perform Tarjan's algorithm on \|g\X${}\E{}$\6
\X12:Make all vertices unseen and all arcs untagged\X;\6
\&{for} ${}(\\{vv}\K\|g\MG\\{vertices};{}$ ${}\\{vv}<\|g\MG\\{vertices}+\|g\MG%
\|n;{}$ ${}\\{vv}\PP){}$\1\6
\&{if} ${}(\\{vv}\MG\\{rank}\E\T{0}{}$)\C{ \\{vv} is still unseen }\1\6
\X13:Perform a depth-first search with \\{vv} as the root, finding the strong
components of all unseen vertices reachable from~\\{vv}\X;\2\2\6
\X17:Print out one representative of each arc that runs between strong
components\X;\par
\U2.\fi

\M{11}\B\X5:Global variables\X${}\mathrel+\E{}$\6
\&{Vertex} ${}{*}\\{vv}{}$;\C{ sweeps over all vertices, making sure none is
left unseen }\par
\fi

\M{12}It's easy to get the data structures started, according to the
conventions stipulated above.

\Y\B\4\X12:Make all vertices unseen and all arcs untagged\X${}\E{}$\6
\&{for} ${}(\|v\K\|g\MG\\{vertices}+\|g\MG\|n-\T{1};{}$ ${}\|v\G\|g\MG%
\\{vertices};{}$ ${}\|v\MM){}$\5
${}\{{}$\1\6
${}\|v\MG\\{rank}\K\T{0};{}$\6
${}\|v\MG\\{untagged}\K\|v\MG\\{arcs};{}$\6
\4${}\}{}$\2\6
${}\\{nn}\K\T{0};{}$\6
${}\\{active\_stack}\K\\{settled\_stack}\K\NULL{}$;\par
\U10.\fi

\M{13}The task of starting a depth-first search isn't too bad either.
Throughout
this part of the algorithm, variable~\|v will point to the current vertex.

\Y\B\4\X13:Perform a depth-first search with \\{vv} as the root, finding the
strong components of all unseen vertices reachable from~\\{vv}\X${}\E{}$\6
${}\{{}$\1\6
${}\|v\K\\{vv};{}$\6
${}\|v\MG\\{parent}\K\NULL;{}$\6
\X14:Make vertex \|v active\X;\6
\&{do}\5
\X15:Explore one step from the current vertex~\|v, possibly moving to another
current vertex and calling~it~\|v\X\5
\&{while} ${}(\|v\I\NULL);{}$\6
\4${}\}{}$\2\par
\U10.\fi

\M{14}\B\X14:Make vertex \|v active\X${}\E{}$\6
$\|v\MG\\{rank}\K\PP\\{nn};{}$\6
${}\|v\MG\\{link}\K\\{active\_stack};{}$\6
${}\\{active\_stack}\K\|v;{}$\6
${}\|v\MG\\{min}\K\|v{}$;\par
\Us13\ET15.\fi

\M{15}Now things get interesting. But we're just doing what any well-organized
spelunker would do when calmly exploring a cave.
There are three main cases,
depending on whether the current vertex stays where it is, moves
to a new child, or backtracks to a parent.

\Y\B\4\X15:Explore one step from the current vertex~\|v, possibly moving to
another current vertex and calling~it~\|v\X${}\E{}$\6
${}\{{}$\5
\1\&{register} \&{Vertex} ${}{*}\|u{}$;\C{ a vertex adjacent to \|v }\6
\&{register} \&{Arc} ${}{*}\|a\K\|v\MG\\{untagged}{}$;\C{ \|v's first remaining
untagged arc, if any }\7
\&{if} (\|a)\5
${}\{{}$\1\6
${}\|u\K\|a\MG\\{tip};{}$\6
${}\|v\MG\\{untagged}\K\|a\MG\\{next}{}$;\C{ tag the arc from \|v to \|u }\6
\&{if} ${}(\|u\MG\\{rank}){}$\5
${}\{{}$\C{ we've seen \|u already }\1\6
\&{if} ${}(\|u\MG\\{rank}<\|v\MG\\{min}\MG\\{rank}){}$\1\5
${}\|v\MG\\{min}\K\|u{}$;\C{ non-tree arc, just update $\|v\MG\\{min}$ }\2\6
\4${}\}{}$\5
\2\&{else}\5
${}\{{}$\C{ \|u is presently unseen }\1\6
${}\|u\MG\\{parent}\K\|v{}$;\C{ the arc from \|v to \|u is a new tree arc }\6
${}\|v\K\|u{}$;\C{ \|u will now be the current vertex }\6
\X14:Make vertex \|v active\X;\6
\4${}\}{}$\2\6
\4${}\}{}$\5
\2\&{else}\5
${}\{{}$\C{ all arcs from \|v are tagged, so \|v matures }\1\6
${}\|u\K\|v\MG\\{parent}{}$;\C{ prepare to backtrack in the tree }\6
\&{if} ${}(\|v\MG\\{min}\E\|v){}$\1\5
\X16:Remove \|v and all its successors on the active stack from the tree, and
mark them as a strong component of the graph\X\2\6
\&{else}\C{ the arc from \|u to \|v has just matured,              making $\|v%
\MG\\{min}$ visible from \|u }\6
\, \&{if} ${}(\|v\MG\\{min}\MG\\{rank}<\|u\MG\\{min}\MG\\{rank}){}$\1\5
${}\|u\MG\\{min}\K\|v\MG\\{min};{}$\2\6
${}\|v\K\|u{}$;\C{ the former parent of \|v is the new current vertex \|v }\6
\4${}\}{}$\2\6
\4${}\}{}$\2\par
\U13.\fi

\M{16}The elements of the active stack are always in order
by rank, and all children of a vertex~\|v in the tree have rank higher
than~\|v. Tarjan's algorithm relies on a converse property: {\sl All
active nodes whose rank exceeds that of the current vertex~\|v are
descendants of~\|v.} (This property holds because the algorithm has constructed
the tree by assigning ranks in preorder, ``the order of succession to the
throne.'' First come \|v's firstborn and descendants, then the nextborn,
and so on.) Therefore the descendants of the current vertex always appear
consecutively at the top of the stack.

Another fundamental property of Tarjan's algorithm is more subtle:
{\sl There is always a way to get from any active vertex to the
current vertex.} This follows from the fact that all mature active vertices~\|u
have $\|u\MG\\{min}\MG\\{rank}<\|u\MG\\{rank}$.  If some active vertex does not
lead to the
current vertex~\|v,
let \|u be the counterexample with smallest rank. Then \|u isn't an
ancestor of~\|v, hence \|u must be mature; hence it leads to the
active vertex $\|u\MG\\{min}$, from which there {\sl is\/} a path to~\|v,
contradicting our assumption.

Therefore \|v and its active descendants are all reachable from each
other, and they must belong to the same strong component. Moreover, if
$\|v\MG\\{min}\K\|v$, this component can't be made any larger. For there is no
arc from any of these vertices to an unseen vertex; all arcs from \|v
and its descendants have already been tagged. And there is no arc from
any of these vertices to an active vertex that is below \|v on the
stack; otherwise $\|v\MG\\{min}$ would have smaller rank than~\|v. Hence all
arcs, if any, that lead from these vertices to some other vertex must
lead to settled vertices. And we know from previous steps of the
computation that the settled vertices all belong to other strong
components.

Therefore we are justified in settling \|v and its active descendants now.
Removing them from the tree of active vertices does not remove any
vertex from which there is a path to a vertex of rank less than $\|v\MG%
\\{rank}$.
Hence their removal does not affect the validity of the $\|u\MG\\{min}$ value
for any vertex~\|u that remains active.

We print out enough information for a reader to verify the
strength of the claimed component easily.

\Y\B\4\D$\\{infinity}$ \5
$\|g\MG{}$\|n\C{ infinite rank (or close enough) }\par
\Y\B\4\X16:Remove \|v and all its successors on the active stack from the tree,
and mark them as a strong component of the graph\X${}\E{}$\6
${}\{{}$\5
\1\&{register} \&{Vertex} ${}{*}\|t{}$;\C{ runs through the vertices of the
                    new strong component }\7
${}\|t\K\\{active\_stack};{}$\6
${}\\{active\_stack}\K\|v\MG\\{link};{}$\6
${}\|v\MG\\{link}\K\\{settled\_stack};{}$\6
${}\\{settled\_stack}\K\|t{}$;\C{ we've moved the top of one stack to the other
}\6
${}\\{printf}(\.{"Strong\ component\ `\%}\)\.{ld\ \%s'"},\39\\{specs}(\|v));{}$%
\6
\&{if} ${}(\|t\E\|v){}$\1\5
\\{putchar}(\.{'\\n'});\C{ single vertex }\2\6
\&{else}\5
${}\{{}$\1\6
\\{printf}(\.{"\ also\ includes:\\n"});\6
\&{while} ${}(\|t\I\|v){}$\5
${}\{{}$\1\6
${}\\{printf}(\.{"\ \%ld\ \%s\ (from\ \%ld\ \%}\)\.{s;\ ..to\ \%ld\ \%s)\\n"},%
\39\\{specs}(\|t),\39\\{specs}(\|t\MG\\{parent}),\39\\{specs}(\|t\MG%
\\{min}));{}$\6
${}\|t\MG\\{rank}\K\\{infinity}{}$;\C{ now \|t is settled }\6
${}\|t\MG\\{parent}\K\|v{}$;\C{ and \|v represents the new strong component }\6
${}\|t\K\|t\MG\\{link};{}$\6
\4${}\}{}$\2\6
\4${}\}{}$\2\6
${}\|v\MG\\{rank}\K\\{infinity}{}$;\C{ \|v too is settled }\6
${}\|v\MG\\{parent}\K\|v{}$;\C{ and represents its own strong component }\6
\4${}\}{}$\2\par
\U15.\fi

\M{17}After all the strong components have been found, we can also compute the
relations between them, without mentioning any cross-connection more than
once. In fact, we built the \\{settled\_stack} precisely so that this task
could be done easily without sorting or searching. If only the strong
components themselves were of interest, this part of the algorithm wouldn't
be necessary.

For this step we use the name \\{arc\_from} for the field we previously
called \\{untagged}. The trick here relies on the fact that all vertices of the
same strong component appear together in \\{settled\_stack}.

\Y\B\4\D$\\{arc\_from}$ \5
$\|x.{}$\|V\C{ utility field \|x will now point to a vertex }\par
\Y\B\4\X17:Print out one representative of each arc that runs between strong
components\X${}\E{}$\6
\\{printf}(\.{"\\nLinks\ between\ com}\)\.{ponents:\\n"});\6
\&{for} ${}(\|v\K\\{settled\_stack};{}$ \|v; ${}\|v\K\|v\MG\\{link}){}$\5
${}\{{}$\5
\1\&{register} \&{Vertex} ${}{*}\|u\K\|v\MG\\{parent};{}$\6
\&{register} \&{Arc} ${}{*}\|a;{}$\7
${}\|u\MG\\{arc\_from}\K\|u;{}$\6
\&{for} ${}(\|a\K\|v\MG\\{arcs};{}$ \|a; ${}\|a\K\|a\MG\\{next}){}$\5
${}\{{}$\5
\1\&{register} \&{Vertex} ${}{*}\|w\K\|a\MG\\{tip}\MG\\{parent};{}$\7
\&{if} ${}(\|w\MG\\{arc\_from}\I\|u){}$\5
${}\{{}$\1\6
${}\|w\MG\\{arc\_from}\K\|u;{}$\6
${}\\{printf}(\.{"\%ld\ \%s\ ->\ \%ld\ \%s\ (e}\)\.{.g.,\ \%ld\ \%s\ ->\ \%ld\ %
\%}\)\.{s)\\n"},\39\\{specs}(\|u),\39\\{specs}(\|w),\39\\{specs}(\|v),\39%
\\{specs}(\|a\MG\\{tip}));{}$\6
\4${}\}{}$\2\6
\4${}\}{}$\2\6
\4${}\}{}$\2\par
\U10.\fi

\N{1}{18}Index. We close with a list that shows where the identifiers of this
program are defined and used.
\fi


\inx
\fin
\con
