Complete the code to create a graph adjacency list using a vector of vectors.
let mut graph: Vec<Vec<usize>> = vec![vec![]; [1]];We create an adjacency list with one vector per node, so the size must be the number of nodes.
Complete the code to add an edge from node u to node v in the adjacency list.
graph[[1]].push(v);We add v to the neighbors list of node u, so the index is u.
Fix the error in the code that tries to find the shortest path in a tree but uses a graph method.
let mut dist = vec![usize::MAX; [1]];Distance vector size must match the number of nodes, not edges or other values.
Fill both blanks to complete the BFS loop that finds shortest paths in a graph.
while let Some([1]) = queue.pop_front() { for &[2] in &graph[u] { // process neighbors } }
We pop node u from the queue and iterate over its neighbors v.
Fill all three blanks to complete the condition that updates distance and pushes neighbors in BFS.
if dist[[1]] == usize::MAX { dist[[2]] = dist[u] + 1; queue.push_back([3]); }
We check if neighbor v is unvisited, update its distance, and add v to the queue.
