Language: C++

#include<iostream>
#include<algorithm>
#include<queue>
#include<mpi.h>
#include<cstring>
using namespace std;
#define INF (1 << 29)
typedef pair< int , int > Pi;

int h, w;
char mas[50][50];
int graph[11][11];
int min_cost[50][50];
Pi gomi[11], st, gl;
int gomi_size, uoo;
int memo[12][1 << 11];
const int dy[] = { 1, 0, 0, -1}, dx[] = { 0, 1, -1, 0};

int rec(int idx, int used)
{
  if(used == (1 << gomi_size) - 1) return 0;
  if(memo[idx][used]) return memo[idx][used];

  int ret = INF;
  for(int i = 0; i < gomi_size; i++){
    if(!(used & (1 << i)) && graph[idx][i] != -1){
      ret = min(ret, rec(i, used | (1 << i)) + graph[idx][i]);
    }
  }

  return memo[idx][used] = ret;
}


int bfs(Pi a, Pi b)
{
  memset( min_cost, -1, sizeof(min_cost));
  queue< Pi > que;
  que.push(a);
  min_cost[a.first][a.second] = 0;
  while(!que.empty()){
    Pi p = que.front(); que.pop();
    if(p == b) return min_cost[p.first][p.second];
    for(int i = 0; i < 4; i++){
      int ny = p.first + dy[i], nx = p.second + dx[i];
      if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
      if(mas[ny][nx] != 'x' && min_cost[ny][nx] == -1){
	min_cost[ny][nx] = min_cost[p.first][p.second] + 1;
	que.push( Pi( ny, nx));
      }
    }
  }
  return -1;
}

int main(int argc, char* argv[])
{
  MPI_Request req1, req2;
  MPI_Status stat;
  int tag = 0, rank, numprocs;
  int rank_buff[11][11];
  vector< Pi > my_bfs; 

  MPI_Init(&argc, &argv);
  MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);

  while(true){
    if(rank == 0){
      cin >> w >> h;
    }
    MPI_Bcast( &w, 1, MPI_INT, 0, MPI_COMM_WORLD);
    MPI_Bcast( &h, 1, MPI_INT, 0, MPI_COMM_WORLD);

    if(w == 0) break;

    gomi_size = 0;
    my_bfs.clear();
    memset( memo, 0, sizeof(memo));

    if(rank == 0){
      for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
          cin >> mas[i][j];
          if(mas[i][j] == '*' || mas[i][j] == 'o'){
            gomi[gomi_size++] = Pi( i, j);
            if(mas[i][j] == 'o') uoo = gomi_size - 1;
          }
        }
      }
    }

    for(int i = 0; i < h; i++){
      MPI_Bcast( mas[i], w, MPI_INT, 0, MPI_COMM_WORLD);
    }

    MPI_Bcast( &gomi_size, 1, MPI_INT, 0, MPI_COMM_WORLD);

    for(int i = 0, foo = 0; i < gomi_size; i++){ //送るプロセスの計算(めんどい
      for(int j = i + 1; j < gomi_size; j++, foo = (foo + 1) % numprocs){
        rank_buff[i][j] = foo;
        if(foo == rank) my_bfs.push_back( Pi(i, j));
      }
    }

    if(rank == 0){
      for(int i = 0; i < gomi_size; i++){
        for(int j = i + 1; j < gomi_size; j++){
          if(rank_buff[i][j] != 0){
            MPI_Isend( &gomi[i], 1, MPI::TWOINT, rank_buff[i][j], tag, MPI_COMM_WORLD, &req1);
            MPI_Isend( &gomi[j], 1, MPI::TWOINT, rank_buff[i][j], tag, MPI_COMM_WORLD, &req2);
          }
        }
      }
      for(int i = 0; i < my_bfs.size(); i++){
        Pi p = my_bfs[i];
        graph[p.first][p.second] = bfs( gomi[p.first], gomi[p.second]);
      }

      for(int i = 0; i < gomi_size; i++){
        for(int j = i + 1; j < gomi_size; j++){
          if(rank_buff[i][j] != 0){
            MPI_Irecv( &graph[i][j], 1, MPI_INT, rank_buff[i][j], tag, MPI_COMM_WORLD, &req1);
            MPI_Wait( &req1, &stat);
            graph[j][i] = graph[i][j];
          }
       }
      }

    } else {
      for(int i = 0; i < my_bfs.size(); i++){
        MPI_Irecv( &st, 1, MPI::TWOINT, 0, tag, MPI_COMM_WORLD, &req1);
        MPI_Irecv( &gl, 1, MPI::TWOINT, 0, tag, MPI_COMM_WORLD, &req2);
        MPI_Wait(&req1, &stat);
        MPI_Wait(&req2, &stat);
        int res = bfs( st, gl);
        MPI_Isend( &res, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &req1);
      }
    }

    
    //巡回セールスマン！！
    //さのぴーさんよろしく
    if(rank == 0){
      int ret = rec( uoo, 1 << uoo);
    
      if(ret != INF) cout << ret << endl;
      else cout << -1 << endl;
    }
  }
  MPI_Finalize();
  return(0);
}

Compiler output:
a.cc:4:9: fatal error: mpi.h: No such file or directory
    4 | #include<mpi.h>
      |         ^~~~~~~
compilation terminated.