Ok, it looks like you have no idea what you're doing, or you're trying to be a robot and write C++ by the book (which actually isn't a good idea, since most books don't have the best examples to explain things).
- Give your vaiables and objects meaningfull names. Instead of 'p', name it 'input' or 'user_input'. Instead of 'n', name it 'user_defined_node'. What you anme them is up to you, but you shouldn't have to read the entire thing to get a feel for what it's used for.
- Look up what an lvalue and rvalue is. ++an_int is not the same as an_int++.
- I think you need to brush up on your conditionals. if(booloean == true) is what an if statement does, so: if(!is_right) equates to if(is_right != true). if(false) will always return false because false != true.
- finally, break it down. Stop trying to construct the whole thing. Put all the little tiny steps into functions. Example: bool is_node_reachable(const node&);, void display_graph(const graph&);, void fill_graph(graph&);. These are just prototypes, but you should get what I mean. It will make it much easier to pinpoint what's being done, and where, when there is only a single place the instructions can occur.
I made this code & took almost 10 hours. But there is a problem in the output.
I've mentioned this earlier. And you saying, I've no idea what i did? You think it was a waste of time??
And what if there is no meaning with variables? Although that is good programming practice, but nothing else.
And yaah, ++an_int is not the same as an_int++. But that doesn't make any major change there.
Look at line 42 ... rear = (rear+1)%q; ... and consider what happens if the enqueue() function gets called more than once.
My suggestion would be to start a new project and copy your queue class over to it. Do some simple tests there to ensure that the class is working as expected before trying to use it in more complicated code.
LTP, you can always give vairables meaningful names, or names that better clarify what they're used for.
I also don't think you understand what the difference between an rvalue and lvalue are: one is a constant, the other is not. You seem to switch between the two with no change in operation: aka you don't use rvalues when you aren't going to change the variable in some cases, which makes using lvalues pointless in the other, similar, scenarios. It's about consistency, not how it works (although it may be in some cases).
It would seem to me that what you're lacking is study. Somthing like this shouldn't take 10 hours to write. That being said, I can only assume you're throwing code at the wall and hoping it sticks. That will never work.