Complete the code to declare an adjacency list for a graph with 5 nodes.
vector<int> graph[[1]];The graph has 5 nodes, so the adjacency list array size should be 5.
Complete the code to add an edge from node 2 to node 3 in the graph.
graph[2].[1](3);
To add an edge, we use push_back to add node 3 to adjacency list of node 2.
Fix the error in the BFS loop to visit all neighbors of current node u.
for (int v : graph[[1]]) { if (!visited[v]) { visited[v] = true; q.push(v); } }
We must iterate over neighbors of current node u, so use graph[u].
Fill both blanks to check if a node is already visited before adding to queue.
if (![1][[2]]) { visited[v] = true; q.push(v); }
We check if visited[v] is false before visiting node v.
Fill all three blanks to create a map of shortest distances from source node s.
vector<int> dist(n, [1]); dist[[2]] = 0; queue<int> q; q.push([3]);
Initialize distances with -1 (unvisited), set dist[s] = 0, and start BFS from s.
