private List<Integer> getSortedNodes(LinkedList[] graph){
        List<Pair<Integer,Integer>> list= new ArrayList<Pair<Integer, Integer>>();
        for(int i=0;i<graph.length;++i){
            list.add(new Pair<Integer, Integer>(i,graph[i].size()));
        }
        Collections.sort(list, new Comparator<Pair<Integer, Integer>>() {
            @Override
            public int compare(Pair<Integer, Integer> o1, Pair<Integer, Integer> o2) {
                return o1.getValue()-o2.getValue();
            }
        });
        List<Integer> result=new ArrayList<Integer>();
        for(Pair<Integer,Integer> pair: list){
            result.add(pair.getKey());
        }
        return result;

    }