Language: C++

/*****include*****/
#include <iostream>
#include <fstream>
#include <queue>

/*****マクロ定義*****/
#define START 0
#define EMPTY 10

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/
char Field[1001][1001];
bool Visited[1001][1001];
int TimeF[1001][1001];

/*****その他関数置き場*****/
int bfs(int sx,int sy,int gx,int gy){
	queue<int> Qx;
	queue<int> Qy;
	int x_now;
	int y_now;
	int x_next;
	int y_next;
	int dx[] = {0,1,0,-1};
	int dy[] = {-1,0,1,0};
	Qx.push(sx);
	Qy.push(sy);
	for(int i=0;i<1001;i++){
		for(int j=0;j<1001;j++){
			Visited[i][j] = false;
			TimeF[i][j] = 0;
		}
	}

	Visited[sy][sx] = true;
	TimeF[sy][sx] = 0;
	while(!(Qx.empty() && Qy.empty())){
		x_now = Qx.front();Qx.pop();
		y_now = Qy.front();Qy.pop();
		//cout << TimeF[y_now][x_now] << endl;
		if(x_now == gx && y_now == gy)	break;
		for(int i=0;i<4;i++){
			x_next = x_now + dx[i];
			y_next = y_now + dy[i];
			if(Field[y_next][x_next] == 'X' || Visited[y_next][x_next]);
			else{
				Qx.push(x_next);
				Qy.push(y_next);
				Visited[y_next][x_next] = true;
				TimeF[y_next][x_next] = TimeF[y_now][x_now] + 1;
			}
		}
	}
	return TimeF[gy][gx];
}
/*****main関数*****/
void main(){
	/*****変数置き場*****/
	int total_time = 0;
	char row[1001];
	int height;
	int width;
	int n;
	int x[] = {0,0,0,0,0,0,0,0,0,0};
	int y[] = {0,0,0,0,0,0,0,0,0,0};
	/*****ファイルオープン*****/	
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return;
	}
	
	/*****処理部*****/
	cin >> height >> width >> n;
	for(int i=0;i<1001;i++){
		for(int j=0;j<1001;j++){
			Field[i][j] = 'X';
			Visited[i][j] = false;
			TimeF[i][j] = 0;
		}
	}
	for(int i=0;i<height;i++){
		cin >> row;
		for(int j=0;j<width;j++){
			Field[i+1][j+1] = row[j];
		}
	}
	/*for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			cout << Field[i][j];
		}
		cout << endl;
	}*/
	for(int i=0;i<height+1;i++){
		for(int j=0;j<width+1;j++){
			switch (Field[i][j]){
			case 'S':
				x[START] = j;
				y[START] = i;
				break;
			case '1':
				x[1] = j;
				y[1] = i;
				break;
			case '2':
				x[2] = j;
				y[2] = i;
				break;
			case '3':
				x[3] = j;
				y[3] = i;
				break;
			case '4':
				x[4] = j;
				y[4] = i;
				break;
			case '5':
				x[5] = j;
				y[5] = i;
				break;
			case '6':
				x[6] = j;
				y[6] = i;
				break;
			case '7':
				x[7] = j;
				y[7] = i;
				break;
			case '8':
				x[8] = j;
				y[8] = i;
				break;
			case '9':
				x[9] = j;
				y[9] = i;
				break;
			}
		}
	}
	/*for(int i=0;i<10;i++){
		cout << x[i] << " ";
	}
	cout << endl;
	for(int i=0;i<10;i++){
		cout << y[i] << " ";
	}
	cout << endl;*/
	for(int i=0;i<n;i++){
		total_time += bfs(x[i],y[i],x[i+1],y[i+1]);
	}
	/*for(int i=0;i<20;i++){
		for(int j=0;j<20;j++){
			cout << Visited[i][j];
		}
		cout << endl;
	}*/
	cout << total_time << endl;
	/*****処理終了後*****/
	fout.close();
	fin.close();
	//delete[] pField;
	//delete[] pVisited;
}

Compiler output:
a.cc:59:1: error: '::main' must return 'int'
   59 | void main(){
      | ^~~~
a.cc: In function 'int main()':
a.cc:73:17: error: return-statement with no value, in function returning 'int' [-fpermissive]
   73 |                 return;
      |                 ^~~~~~