Menu Close

Chef’s Binary Tree…-FTC

Chef has a binary tree. The binary tree consists of 1 or more nodes. Each node has a unique integer id. Each node has up to 2 children, which are identified by their ids, and each node is the child of at most 1 other node. A node X is considered to be an ancestor of node Y if node Y is a child of node X or if there is some node Z for which X is an ancestor of Z and Y is a child of Z. No node is an ancestor of itself. A special node called the root node is an ancestor of all other nodes.

Chef has forgotten which node of his tree is the root, and wants you to help him to figure it out. Unfortunately, Chef’s knowledge of the tree is incomplete. He does not remember the ids of the children of each node, but only remembers the sum of the ids of the children of each node.

Input begins with an integer T, the number of test cases. Each test case begins with an integer N, the number of nodes in the tree. N lines follow with 2 integers each: the id of a node, and the sum of the ids of its children.
The second number will be 0 if the node has no children.

For each test case, output on a line a space separated list of all possible values for the id of the root node in increasing order.
It is guaranteed that at least one such id exists for each test case.

testcase=int(input('Enter the number of test cases: '))
for i in range(0,testcase):
    n=int(input("Enter the n number: "))
    for j in range(0,n):
        temp=int(input('Enter the id node: '))
        temp1=int(input('Enter the sum of ids of the children: '))

Enter the number of test cases: 1
Enter the n number: 4
Enter the id node: 1
Enter the sum of ids of the children: 5
Enter the id node: 2
Enter the sum of ids of the children: 0
Enter the id node: 3
Enter the sum of ids of the children: 0
Enter the id node: 4
Enter the sum of ids of the children: 0

4 0

Morae Q!

->Convert Numbers into Roman Numerals
->Given the string s, return the size of the longest sub-string
->Given an array of string words. Return all strings in words which is sub-string of another word in any order.
->Return the minimum positive value of startValue such that the step by step is never less than 1.
->Given the number k, return the minimum number of Fibonacci.
->Given a string s of zeros and ones, return the maximum score after splitting the string
->Given a sorted array and a value x,Write a efficient functions to find floor of x.
->Print all numbers less than n which are having digits only 3 or 7 or both.
->Function that returns true if given array can be divided into pairs.
->Find the smallest element in the list that is larger than the given target.
->Print the First N prime numbers.
->The Chef’s Binary Tree.
->The minimum number of strikes he will have to make.(so that all his enemies have the same name)
->Sum of Natural Numbers.
->Sum of the Input.
->Find the Sum of the Series: 1 + 1/2 + 1/3 + .. + 1/N.
->Put Even and Odd elements in a List into Two Different Lists.
->Python Program to Merge Two Lists and Sort it.
->Median of Three.
->Python Program to Find the Largest Number in a List.