Directed and undirected graph implementation