/** Directed graph implemented using adjacency list.
 *  Vertices are stored in a list, each vertex has a list of vertices
 *  describing its edges.
 *
 * Data structures, assignment 5
 * 0440949 Andreas van Cranenburgh <andreas@unstable.nl>
 *
 * */
public class Graph {
	java.util.List<Vertex> vertices;
	
	/** Creates a new instance of Graph */
	public Graph() {
		vertices = new java.util.Vector<Vertex>();
	}

	void add(Vertex v) {
		vertices.add(v);
		/* infer the index of this vertex from the current size: */
		v.index = vertices.size() - 1;
	}

	public Vertex get(int i) {
		return vertices.get(i);
	}
	
	public int getNumV() {
		return vertices.size();
	}
	
	public String toString () {
		String result = "";
		for (int a = 0; a < vertices.size(); a++)
			result += vertices.get(a) + ": " + (vertices.get(a)).edges + "\n";
		return result;
	}
}

class Vertex {
	java.util.List<Vertex> edges;
	int ring, left, right, index;

	Vertex(int ring, int left, int right) {
		edges = new java.util.Vector<Vertex>();
		this.ring = ring;
		this.left = left;
		this.right = right;
	}
	
	/* add an edge from this vertice to v */
	void add(Vertex v) {
		this.edges.add(v);
	}

	public java.util.Iterator<Vertex> edgeIterator(int source) {
	      return edges.listIterator(source);
	}
		
	public String toString () {
		return index + ""; // + "=" + ring + ":" + left + "-" + right;
	}
}
