/* An instance of this class, which extends OutDeg1Graph, represents an ** outdegree-1 graph (i.e., a directed graph in which each node has ** exactly one edge emanating from it). ** It augments its parent class by introducing new observer methods that ** provide useful information about the graph. ** ** Authors: R. McCloskey and < STUDENT's NAME > ** Date: November 2022 ** Collaborated with: ... ** Known Defects: ... */ public class OutDeg1GraphPlus extends OutDeg1Graph { // instance variables // ------------------ protected int[] rep; // rep[v] = x means that node x is the representative // node of the component in which node v lies. protected int[] distToCycle; // distToCycle[v] = d means that d is the // length of the shortest path starting at // node v that ends at a node lying on a cycle protected int numComponents; // # of components in this graph // constructor // ----------- /* Establishes this graph as the one described by the given array. */ public OutDeg1GraphPlus(int[] arcs) { super(arcs); // call the parent class's constructor // Initialize the "new" instance variables with values // indicating that the relevant values are yet to be computed. numComponents = -1; final int N = this.numNodes(); rep = new int[N]; distToCycle = new int[N]; // Place a "dummy" value into each array element, indicating // that the relevant value has not yet been computed. for (int i=0; i != N; i++) { rep[i] = -1; distToCycle[i] = -1; } } /* Reports whether or not nodes v and w are ** in the same component of this graph. */ public boolean inSameComponent(int v, int w) { return true; // STUB! } /* Returns the length of the shortest path from node v that ** reaches a node that lies on a cycle. */ public int distanceToCycle(int v) { return -16; // STUB! } /* Reports whether or not node v lies on a cycle. */ public boolean onCycle(int v) { return true; // STUB! } /* Returns the number of components in this graph. */ public int numComponents() { return -7; // STUB! } // private utilities // ----------------- /* Resolves the specified node, which is to say that the correct ** values are computed and stored in rep[v] and distToCycle[v]. ** If implemented well, the same can be said for rep[w] and ** distToCycle[w], where w is any node reachable from v. */ protected void resolve(int v) { } }