Can anyone give me a code of using adjacency lists to represent a graph using arrays only( perhaps by using an 2D array).

I was in the same position as you are just a few weeks back. In fact, I haven’t even practiced enough graph problems. I wanted answers only in terms in what I know. But trust me, arrays are a lot more harder to maintain adjacency lists. Anyway, you can check these out

http://www.iarcs.org.in/inoi/online-study-material/topics/graphs-representation.php

http://web.stanford.edu/class/cs97si/06-basic-graph-algorithms.pdf

A better option would be to use an array of vectors or a vector of vectors whose size can be adjusted dynamically, you don’t have to specify it in advance. To use a vector of vectors to maintain an adjacency list, google how it works and for a better understanding refer this, an implementation of the FIREESC problem

Hope it helps!