Help with LSTGRPH

Can someone please help me with this problem? I have looked up the editorial and found that I have the right idea and also my solution match with some others. I have used BFS to get the answer. But I can’t seem to find whats wrong :frowning:
Code: https://www.codechef.com/viewsolution/13779107

Thank you in advance!

1 Like

There’s a bug in your solution.

cout << ((i < start) ? (ans[i]) : (ans[i] ^ (k-1))) << " ";

You are assuming that i>=start implies that vertex i is in the last component, but that is not always so. start is the first vertex of the last component, but one or more of the earlier components can have vertices with index greater than start. Hope this helps :slight_smile:

2 Likes

Thank you for your answer :slight_smile:

No problem! Did that fix it?

1 Like

Yes, it did indeed. :smiley:

Silly me! :3

1 Like