private void constructSLS() {
        for (int row = 0; row < N; row++) {
            for (int col = 0; col < M; col++) {
                makeSet(getIndex(row, col));
            }
        }
        
        for (int row = 0; row < N; row++) {
            for (int col = 0; col < M; col++) {
                int color = board[row][col];
                int id = getIndex(row, col);
                int leftId  = left(id);
                int upperId = upper(id);
                if (leftId >= 0 && getColor(leftId) == color) {
                    union(id,leftId);
                }
                if (upperId >= 0 && getColor(upperId) == color) {
                    union(id, upperId);
                }
            }
        }
    }