When submitting a solution in C++, please select either C++14 (GCC 6-32) or C++17 (GCC 7-32) as your compiler. ×

Tenac-ious-'s blog

By Tenac-ious-, history, 3 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

»
3 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).

»
3 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).

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

»
3 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:

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

yes,got it