For this Question: Given a binary tree with root 1. You have to make some other node as the root such that all conditions of a binary tree is satisfied. Print all nodes other than 1 that can be made as the root of the tree in sorted order.
Note - You cannot add/remove a node. You cannot break any edge.First line contains the integer N, denoting the number of nodes in the binary tree.
Next N lines contains two integers denoting the left and right child of the i'th node respectively. 
If the node doesn't have a left or right child, it is denoted by '-1'

1 <= N <= 100000Print in a single line all nodes other than 1 that can be made as the root. You must print in increasing order.Sample Input 1:
5
2 4
5 -1
-1 -1
-1 3
-1 -1
Sample output 1:
2 3 4 5

Explanation: Given binary tree 
                1
               /  \
             2     4
            /        \
          5           3
One possible configuration of tree when 4 is made as the root
                4
               /  \
             1     3
            /      
           2 
         / 
        5  , I have written this Solution Code: import java.util.*;
import java.io.*;
class Node
{
    int data;
    Node left;
    Node right;
    Node(int data)
    {
        this.data=data;
        left = right = null;
    }
}
class Main
{
    static void printSorted(Node root, ArrayList<Integer> ar)
    {
        if (root == null) {
            return;
        }

        Queue<Node> queue = new LinkedList<Node>();
        queue.add(root);

        while(!queue.isEmpty())
        {
            int curr=queue.size();
            for(int i=0;i<curr;i++)
            {
                Node temp=queue.poll();

                boolean m=(temp.left!=null && temp.right!=null);
                if(m==false)
                {
                    if(temp.data!=1)
                    {
                        ar.add(temp.data);
                    }
                }

                if(temp.left!=null)
                {
                    queue.add(temp.left);
                }
                if(temp.right!=null)
                {
                    queue.add(temp.right);
                }
            }
        }

        Collections.sort(ar);
        for(int k=0;k<ar.size();k++)
        {
            System.out.print(ar.get(k)+" ");
        }
    }

    public static void main(String args[]) throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        Node head=new Node(1);
        Node arr1[]=new Node[n+1];
        arr1[1]=head;
        for(int i=1;i<n+1;i++)
        {
            String str[]=br.readLine().trim().split(" ");
            int a=Integer.parseInt(str[0]);
            int b=Integer.parseInt(str[1]);
            if(a!=-1){
                Node newNode = new Node(a);
                arr1[i].left = newNode;
                arr1[a] = newNode;
            }
            if(b!=-1){
                Node newNode = new Node(b);
                arr1[i].right = newNode;
                arr1[b] = newNode;
            }
        }
        ArrayList<Integer> arr = new ArrayList<>();
        printSorted(head,arr);
    }
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?