converted to adjacency list