#include #include #define Vertex int struct digraph { int V; int A; int *adj; }; typedef struct digraph *Digraph; typedef struct node *link; struct node { Vertex w; link next; }; link NEW (Vertex w, link next) { link x = malloc(sizeof *x); x->w = w; x->next = next; return x; } Digraph DIGRAPHinit (int V) { Digraph G = malloc(sizeof *G); G->V = V; G->A = 0; G->adj = malloc(V * sizeof(link)); int v; for (v = 0; v < V; v++) G->adj[v] = NULL; return G; } void DIGRAPHinsertA (Digraph G, Vertex v, Vertex w) { link p; if (v == w) return; for (p = G->adj[v]; p != NULL; p = p->next) if (p->w == w) return; G->adj[v] = NEW(w, G->adj[v]); G->A++; }