UVa #112 Tree Summing

Posted by unclerojelio on Stack Overflow See other posts from Stack Overflow or by unclerojelio
Published on 2010-03-13T03:29:47Z Indexed on 2010/03/13 3:37 UTC
Read the original article Hit count: 402

Filed under:
|
|

I'm working on UVa #112 Tree Summing. I have what I think should be a working solution but it is not accepted by the online judge due to a basic misunderstanding of the problem on my part. Consider the following inputs:

-1 (-1()())
77 (77(1()())())

or diagrammatically, the trees look like:

  -1              77
 /   \           /  \
()    ()        1    ()
               / \
              ()  ()

According to at least two working solutions, the correct output for the above inputs is:

yes
no

However, I don't understand why the second one should be 'no'. It looks to me like the rightmost path of the tree should give the proper sum. What am I missing?

© Stack Overflow or respective owner

Related posts about uva

  • UVA #10410 Tree Reconstruction

    as seen on Stack Overflow - Search for 'Stack Overflow'
    I have worked on UVA 10410 Tree Reconstruction several days. But I can't get the correct answer unitl now. I have used an algorithm similar to the one which we always use to recovery a binary tree through the preorder traversal and the inorder traversal. But it can't work. Can anyone help me? Thanks… >>> More

  • 3n+1 problem at UVa

    as seen on Stack Overflow - Search for 'Stack Overflow'
    Hello, I am having trouble with the first question in the Programming Challenges book by Skiena and Revilla. I keep getting a "Wrong Answer" error message, and I don't know why. I've ran my code against the sample input, and I keep getting the right answer. Anyways, if anyone could help me, I would… >>> More

  • UVa #112 Tree Summing

    as seen on Stack Overflow - Search for 'Stack Overflow'
    I'm working on UVa #112 Tree Summing. I have what I think should be a working solution but it is not accepted by the online judge due to a basic misunderstanding of the problem on my part. Consider the following inputs: -1 (-1()()) 77 (77(1()())()) or diagrammatically, the trees look like: -1… >>> More

  • Uva's 3n+1 problem

    as seen on Stack Overflow - Search for 'Stack Overflow'
    I'm solving Uva's 3n+1 problem and I don't get why the judge is rejecting my answer. The time limit hasn't been exceeded and the all test cases I've tried have run correctly so far. import java.io.*; public class NewClass{ /** * @param args the command line arguments */ … >>> More

  • UVA Online Judge 3n+1 : Right answer is Wrong answer

    as seen on Stack Overflow - Search for 'Stack Overflow'
    Ive been toying with this problem for more than a week now, I have optimized it a lot, I seem to be getting the right answer, since it's the same as when I compare it to other's answers that got accepted, but I keep getting wrong answer. Im not sure what's going on! Anyone have any advice? I think… >>> More

Related posts about trees