#include<bits/stdc++.h>
using namespace std;
// Function to add an edge to the graph
void addEdge(vector<vector<int>> &adjList, int u, int v) {
adjList[u].push_back(v); // Add v to u's list
adjList[v].push_back(u); // Add u to v's list (for an undirected graph)
}
// Function to print the adjacency list representation of the graph
void printGraph(const vector<vector<int>> &adjList) {
for (int i = 0; i < adjList.size(); i++) {
cout << "Vertex " << i << ":";
for (int j : adjList[i]) {
cout << " -> " << j;
}
cout << endl;
}
}
int main() {
int numVertices = 5; // Number of vertices in the graph
// Create an adjacency list
vector<vector<int>> adjList(numVertices);
// Add edges
addEdge(adjList, 0, 1);
addEdge(adjList, 0, 4);
addEdge(adjList, 1, 2);
addEdge(adjList, 1, 3);
addEdge(adjList, 1, 4);
addEdge(adjList, 2, 3);
addEdge(adjList, 3, 4);
// Print the adjacency list
printGraph(adjList);
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCi8vIEZ1bmN0aW9uIHRvIGFkZCBhbiBlZGdlIHRvIHRoZSBncmFwaAp2b2lkIGFkZEVkZ2UodmVjdG9yPHZlY3RvcjxpbnQ+PiAmYWRqTGlzdCwgaW50IHUsIGludCB2KSB7CiAgICBhZGpMaXN0W3VdLnB1c2hfYmFjayh2KTsgLy8gQWRkIHYgdG8gdSdzIGxpc3QKICAgIGFkakxpc3Rbdl0ucHVzaF9iYWNrKHUpOyAvLyBBZGQgdSB0byB2J3MgbGlzdCAoZm9yIGFuIHVuZGlyZWN0ZWQgZ3JhcGgpCn0KCi8vIEZ1bmN0aW9uIHRvIHByaW50IHRoZSBhZGphY2VuY3kgbGlzdCByZXByZXNlbnRhdGlvbiBvZiB0aGUgZ3JhcGgKdm9pZCBwcmludEdyYXBoKGNvbnN0IHZlY3Rvcjx2ZWN0b3I8aW50Pj4gJmFkakxpc3QpIHsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgYWRqTGlzdC5zaXplKCk7IGkrKykgewogICAgICAgIGNvdXQgP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