Complete the code to declare a graph vertex as an integer variable named 'vertex'.
int [1] = 5;
The variable representing a graph vertex is commonly named 'vertex'.
Complete the code to add an edge between two vertices u and v in an undirected graph using adjacency list.
adjacencyList[u].push_back([1]);To add an edge from vertex u to vertex v, we push v into u's adjacency list.
Fix the error in the code to correctly represent a weighted directed edge from u to v with weight w.
adjacencyList[u].push_back(std::make_pair([1], [2]));
For a weighted directed graph, we add a pair of (vertex, weight) to adjacency list of u.
Fill both blanks to check if an edge from vertex u to vertex v exists in an undirected graph adjacency list.
for (auto [1] : adjacencyList[u]) { if ([2] == v) { return true; } }
We iterate over neighbors of u and check if any neighbor equals v.
Fill all three blanks to create a weighted undirected edge between u and v with weight w in adjacency list.
adjacencyList[u].push_back(std::make_pair([1], [2])); adjacencyList[[3]].push_back(std::make_pair(u, w));
For undirected weighted graphs, add edge (v, w) to u's list and (u, w) to v's list.
