Complete the code to declare a graph using adjacency list representation.
std::vector<std::vector<int>> graph([1]);The number 5 initializes the graph with 5 nodes, creating an adjacency list for each node.
Complete the code to add an edge from node 1 to node 2 in the graph.
graph[[1]].push_back(2);
Index 1 represents node 1, so adding 2 to its adjacency list creates an edge from node 1 to node 2.
Fix the error in the code to correctly check if a graph has a cycle using DFS.
if (visited[node] == [1]) return true;
Visited state 1 means the node is currently in the recursion stack, indicating a cycle if revisited.
Fill both blanks to complete the code that distinguishes a tree from a graph.
bool isTree = (edges == nodes - 1) && !graph.[1](); bool hasCycle = graph.[2]();
A tree must be connected (isConnected) and have no cycles (detectCycle).
Fill all three blanks to complete the code that models a graph with cycles and multiple parents.
graph[[1]].push_back([2]); if (graph[[3]].size() > 1) { // Node has multiple parents }
Adding an edge from node 1 to 2, then checking if node 2 has multiple parents by size of adjacency list.
