Please anybody help to get why I am getting wrong answer in questionYour text to link here... my solution is Your text to link here... I am finding all connected components in the graph and assigning a color to it and the two nodes having same color print "YES" else print<<"NO"
Auto comment: topic has been updated by Tenac-ious- (previous revision, new revision, compare).
Auto comment: topic has been updated by Tenac-ious- (previous revision, new revision, compare).
just make the edge bi-directional then it would work fine.. because while traversing you may reach on either of the edges first so they need to be connected from both dirn..
In your code you are adding directed edge from v[i].second to v[i+1].second
like this --> adj[v[i].second].push_back(v[i+1].second);
But you have to add undirected edges, as you can go backward also :
adj[v[i].second].push_back(v[i+1].second);
adj[v[i+1].second].push_back(v[i].second);
corrected AC code:
yes,got it