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
Code: Solution: 13779107 | CodeChef
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
2 Likes
Thank you for your answer
No problem! Did that fix it?
1 Like