Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <tuple>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(c) (c).begin(), (c).end()
const int inf = 1 << 28;
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};

int w, h;

inline bool inrect(int x, int y){
    return 0 <= x && x < h && 0 <= y && y < w;
}

int solve(vector<string>& c){
    vector<int> xs, ys;
    rep(i, h)rep(j, w){
        if(c[i][j] == 'o')xs.insert(xs.begin(), i), ys.insert(ys.begin(), j);
        if(c[i][j] == '*')xs.push_back(i), ys.push_back(j);
    }
    int n = (int)xs.size();
    vector<vector<int> > costs(n, vector<int>(n, inf));
    rep(i, n){
        vector<vector<int> > mem(h, vector<int>(w, inf)); mem[xs[i]][ys[i]] = 0;
        typedef tuple<int, int, int> State;
        priority_queue<State> q;
        for(q.emplace(0, xs[i], ys[i]); !q.empty();){
            int cost, x, y;
            tie(cost, x, y) = q.top(); q.pop();
            if(mem[x][y] != -cost)continue;
            rep(k, 4){
                int nx = x + dx[k], ny = y + dy[k];
                if(!inrect(nx, ny) || c[nx][ny] == 'x' || mem[nx][ny] <= 1 - cost)continue;
                mem[nx][ny] = 1 - cost;
                q.emplace(-mem[nx][ny], nx, ny);
            }
        }
        rep(j, n)costs[i][j] = mem[xs[j]][ys[j]];
    }
    if(find(all(costs[0]), inf) != costs[0].end())return -1;
    vector<int> mem(1 << n, inf); mem[1 << 0] = 0;
    typedef tuple<int, int, int> State;
    priority_queue<State> q;
    for(q.emplace(0, 1 << 0, 0); !q.empty();){
        int cost, vis, v;
        tie(cost, vis, v) = q.top(); q.pop();
        if(mem[vis] != -cost)continue;
        if(vis == (1 << n) - 1)return -cost;
        rep(i, n){
            if(vis >> i & 1 || mem[vis | 1 << i] <= costs[v][i] - cost)continue;
            mem[vis | 1 << i] = costs[v][i] - cost;
            q.emplace(-mem[vis | 1 << i], vis | 1<< i, i);
        }
    }
    return -1;
}

int main(){
    while(cin >> w >> h, w|h){
        vector<string> c(h);
        rep(i, h)cin >> c[i];
        cout << solve(c) << '\n';
    }
    return 0;
}

Compiler output:
a.cc: In function 'int solve(std::vector<std::__cxx11::basic_string<char> >&)':
a.cc:45:12: error: no matching function for call to 'find(std::vector<int>::iterator, std::vector<int>::iterator, const int&)'
   45 |     if(find(all(costs[0]), inf) != costs[0].end())return -1;
      |        ~~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/locale_facets.h:48,
                 from /usr/include/c++/14/bits/basic_ios.h:37,
                 from /usr/include/c++/14/ios:46,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note:   template argument deduction/substitution failed:
a.cc:45:12: note:   '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'std::istreambuf_iterator<_CharT>'
   45 |     if(find(all(costs[0]), inf) != costs[0].end())return -1;
      |        ~~~~^~~~~~~~~~~~~~~~~~~~