Tenac-ious-'s blog

By Tenac-ious-, history, 4 years ago, In English

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"

  • Vote: I like it
  • +1
  • Vote: I do not like it

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Tenac-ious- (previous revision, new revision, compare).

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Tenac-ious- (previous revision, new revision, compare).

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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..

»
4 years ago, # |
  Vote: I like it +6 Vote: I do not like it

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:

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

yes,got it