protected Integer getTreeHeight(int root,LinkedList<Integer>[] graph,int threshold){
        LinkedList<Integer> stack=new LinkedList<Integer>();
        boolean[] visited=new boolean[graph.length];
        int height=0;
        stack.push(root);
        stack.push(-1);
        visited[root]=true;
        while (!stack.isEmpty()){
            for(int i=stack.pollLast();i!=-1;i=stack.pollLast()){
                LinkedList<Integer> adjacentNodes=graph[i];
                for(Integer node : adjacentNodes){
                    if(!visited[node]){
                        visited[node]=true;
                        stack.push(node);
                    }
                }
            }
            if(++height>threshold) return null;
            if(!stack.isEmpty()){
                stack.push(-1);

            }
        }
        return height;
    }