How should i handle input for this?

I have understood the approach for solving this but confused for how to take input and solve.Should i take input in form of matrix?

no just take two variables x and y
and add in adjancy list
like this
adjlist[x].push_back(y);
or call addAdjlist(x,y) fun

If i want to do with array there must be some way right? like 2d array or something

This is ques of graph so just got oconfused Can i take normal 2 arrays or there should be matrix or what

make vector of vectors
vector<vector< int>>adjList;
now
cin>>x>>y;
adjList[x].push_back(y);

this is same as 2D array

Isnt there some pure non recursive way to do this?

you have to use recursion

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.