public void addEdge(int v, int w) throws InvalidEdgeException,
			SelfLoopExistsException, ParallelEdgeExistsException
	{
		// check for invalid edge
		if (v < 0 || v >= V || w < 0 || w >= V)
			throw new InvalidEdgeException("Invalid edge : " + v + "-" + w);

		if (v == w)
			throw new SelfLoopExistsException("Self loops not allowed : " + v
					+ "-" + w);

		for (int a : adj[v])
			if (a == w)
				throw new ParallelEdgeExistsException(
						"Parallel edges not allowed : " + v + "-" + w);

		if (!adj[v].contains(w)) // this condition is needed only if adjacency
									// lists are presented in the input stream.
									// Since edges v-w and w-v are explicitly
									// specified in the lists care should be
									// taken to not to insert edges twice
		{
			adj[v].add(w);
			adj[w].add(v);
			E++;
		}

	}