The tree algorithm wrote. It is necessary to write an algorithm for counting the number of vertices, the sum of the subtrees is less than 500.

Closed due to the fact that the essence of the question is not clear to the participants by cheops , user194374, Kromster , gecube , Bald 6 Jul '16 at 4:50 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 6
    @Ksenia, you in vain change your questions so that the answers given for the previous formulation of the question become completely inadequate . Alter the question, complementing it, rather than deleting all the previous text. - avp

1 answer 1

  • Modify your tree so that each node contains the "sum of its subtrees" (depending on what you put into this concept) and the number of vertices in the subtrees.

The general meaning here is that now any operation rebuilding the tree must also update these fields.

That is, if you add a node, then you need to run from it up to the root and update the number of vertices and your famous amounts of its subtrees .

  • Recursively go around the tree from above and, if you find a node whose sum of subtrees is <500, then print the number of vertices on the screen.