public boolean connected(int s, int lo, int hi) {
            if (connected == null) connected = new boolean[N];
            Arrays.fill(connected, false);
            
            boolean[] localConnected = new boolean[hi-lo];
            int lConnN = 0; // number of local connections
            
            ArrayDeque<Integer> queue = new ArrayDeque<>();
            queue.add(s);
            
            while(!queue.isEmpty()) {
                Integer i = queue.remove();
                if (!connected[i]) {
                    connected[i] = true;
                    for (int j : adj[i]) {
                        if (!connected[j]) queue.add(j);
                    }
                    
                    if (i >= lo && i < hi && (!localConnected[i-lo])) {
                        localConnected[i-lo] = true;
                        lConnN++;
                        if (lConnN >= hi-lo) return true;
                    }
                }
            }
            
            return false;
        }