Complete the code to initialize the in-degree vector with zeros for each node.
let mut in_degree = vec![[1]; num_nodes];The in-degree vector should be initialized with zeros for all nodes before counting edges.
Complete the code to push nodes with zero in-degree into the queue.
for node in 0..num_nodes { if in_degree[node] == [1] { queue.push_back(node); } }
Nodes with zero in-degree have no dependencies and should be added to the queue first.
Fix the error in the code that decreases the in-degree of adjacent nodes.
for &adj in &graph[node] { in_degree[adj] [1] 1; if in_degree[adj] == 0 { queue.push_back(adj); } }
We decrease the in-degree of adjacent nodes by 1 when we remove an edge.
Fill both blanks to correctly build the adjacency list and update in-degree counts.
for &(src, dest) in edges.iter() { graph[[1]].push( [2] ); in_degree[dest] += 1; }
The adjacency list is built by adding destination nodes to the source node's list. The in-degree of the destination node increases by 1.
Fill all three blanks to complete the main loop that processes nodes in topological order.
while let Some(node) = queue.pop_front() { topo_order.push(node); for &adj in &graph[[1]] { in_degree[[2]] [3] 1; if in_degree[adj] == 0 { queue.push_back(adj); } } }
We process the current node, then for each adjacent node, decrease its in-degree by 1. If in-degree becomes zero, add it to the queue.
