now using adjacency list instead of marix