//
// main.cpp
// Adjacency List
//
// Created by Himanshu on 26/11/22.
//
#include <iostream>
#include <vector>
using namespace std;
#define N 5
//N = number of nodes in graph
void printAdjacencyList (vector<int> graph[N+1]) {
for (int i=1; i<=N; i++) {
cout<<i<<": ";
for (int j=0; j<graph[i].size(); j++) {
cout<<graph[i][j]<<" ";
}
cout<<endl;
}
}
int main() {
vector<int> graph[N+1];
graph[1].push_back(2);
graph[2].push_back(1);
graph[2].push_back(4);
graph[3].push_back(4);
graph[3].push_back(5);
graph[4].push_back(2);
graph[4].push_back(3);
graph[4].push_back(5);
graph[5].push_back(3);
graph[5].push_back(4);
cout<<"Graph G (Adjacency List):"<<endl;
printAdjacencyList(graph);
return 0;
}
Ly8KLy8gIG1haW4uY3BwCi8vICBBZGphY2VuY3kgTGlzdAovLwovLyAgQ3JlYXRlZCBieSBIaW1hbnNodSBvbiAyNi8xMS8yMi4KLy8KCiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHZlY3Rvcj4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBOIDUKIAovL04gPSBudW1iZXIgb2Ygbm9kZXMgaW4gZ3JhcGgKdm9pZCBwcmludEFkamFjZW5jeUxpc3QgKHZlY3RvcjxpbnQ+IGdyYXBoW04rMV0pIHsKICAgICAKICAgIGZvciAoaW50IGk9MTsgaTw9TjsgaSsrKSB7CiAgICAgICAgY291dDw8aTw8IjogIjsKICAgICAgICBmb3IgKGludCBqPTA7IGo8Z3JhcGhbaV0uc2l6ZSgpOyBqKyspIHsKICAgICAgICAgICAgY291dDw8Z3JhcGhbaV1bal08PCIgIjsKICAgICAgICB9CiAgICAgICAgY291dDw8ZW5kbDsKICAgIH0KfQogCmludCBtYWluKCkgewogICAgdmVjdG9yPGludD4gZ3JhcGhbTisxXTsKICAgICAKICAgIGdyYXBoWzFdLnB1c2hfYmFjaygyKTsKICAgIGdyYXBoWzJdLnB1c2hfYmFjaygxKTsKICAgIGdyYXBoWzJdL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