Processes the graph, seems to be working for examples 0, 1, and 2.