Properly builds graph with adjacency linked list rather than a hashmap.