10459 - The Tree Root

All about problems in Volume 104. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

ebb
New poster
Posts: 7
Joined: Sat Nov 19, 2016 8:44 pm

Re: 10459 - The Tree Root

Post by ebb »

ebb wrote: Sat Jun 10, 2017 11:37 pm Hi everyone,

I'm having trouble with this problem. My code (Java) passes all the inputs in this thread and in uDebug, but gets Runtime Error in the judge. I'm pretty sure it is the code that reads the input, because when I wrap it in a try catch I get Wrong Answer. When I remove the actual algorithm instead, I keep getting RE. When catching the exception, it doesn't matter if I stop completely, simply go to the next test case or ignore the exception: I always get Wrong Answer.

Here's my code in case someone can give me a hint of what could be wrong. I've removed the algorithm so we can focus on the input-reading code.

Edit: I removed the code, as I found my mistake.
I found the error. I was assuming that the input is just like shown in the statement: 1 line for number of nodes and 1 line for each node. It turns out this is not the case: the statement doesn't specify that, so each number could be in its own line, or there could be just 1 line with all the test cases.

I've added examples to uDebug.

For solutions coded in C/C++ it shouldn't be a problem. For Java with Scanner it should be ok too, but if you use a Reader for better performance, you have to consider this kind of input.
Post Reply

Return to “Volume 104 (10400-10499)”