Sorry to say that but I think this quote from the problem is wrong “If there are multiple solutions, you may output any one.”.
Please check this problem one more time.
No its correct , there can be multiple solutions too…
Yes, but I don’t think all the correct solutions are considered.
“any one”… Just output 1 of them…
If you’re getting a WA, then most probably the answer you’re outputting is not one of the correct answers.
Whatever solution you print, the checker makes a graph for it and checks if it satisfies the condition of question, if it satisfies, you get AC verdict. So don’t worry, any correct solution is a correct solution.
Edit:- I am not sure if Codechef uses this method.
Only the contest panel can verify the correctness of checker. How can you be sure that checker has no bug, or what algo it uses?
I saw on codeforces one time that they use this method, so I assumed Codechef uses the same. If Codechef doesn’t, then I am sorry for the wrong information.
Please use the comment section of the problem for such matter.