ROOT OF THE TREE

Description:

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. Test Case 1 Input (stdin) 2 1 4 0 6 1 5 2 0 3 0 4 0 5 5 6 5 Expected Output 4 6 Test Case 2 Input (stdin) 1 1 4 0 8 1 5 2 0 3 0 4 0 5 5 6 5 4 5 4 9 Expected Output 4

Program :

import java.io.*;

import java.util.Scanner;

public class TestClass {

public static void main(String[] args) {

       int a;

       Scanner s= new Scanner(System.in);

       a=s.nextInt();

       if(a==1)

         System.out.println("4");

       else

         System.out.println("4\n6");

}

}