Added efficient way to print both undirected and directed graphs