I was thinking of ways to implement an adjacency list for a graph and thought a nested map might be a good idea(because of the fast lookup times) for the outer map I can say map.put but for the inner map which is unnamed how do I put the values in
Scanner sc = new Scanner(System.in);
Map<Integer,Map<Integer,Integer>> graph = new HashMap<>();
int V = sc.nextInt();
int E = sc.nextInt();
for(int i=0;i<E;i++){
int v1 = sc.nextInt();
int v2 = sc.nextInt();
int w = sc.nextInt();
graph.put(v1, Map.entry(v2, w));
graph.put(v2, Map.entry(v1, w));
}
where v1 and v2 are nodes/vertices of the graph and w is the weight/edge between two vertices
does anyone have any idea? thanks in advance:)