Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cstring>
#include <queue>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define MP make_pair
using namespace std;

typedef vector<int> vi;
typedef pair<int, int> P;

int n;
int stage[16][17];
int ans;

int random[16];

void dfs(int rest, int time){
	if(ans <= time) return;
	if(rest == 0){
		//cout << time << endl;
		ans = min(ans, time);
		return;
	}

	int res = 2<<29;
	for(int i = 0; i < n; i++){
		if(!((rest>>random[i])&1)) continue;
		int nexttime = stage[random[i]-1][0];
		for(int j = 1; j <= n; j++){
			if(((rest>>j)&1)) continue;
			nexttime = min(nexttime, stage[random[i]-1][j]);
		}
		int val = ~(1<<random[i]);
		dfs(rest&val, time+nexttime);
	}
}

int main(){
	//freopen("test.txt", "r", stdin);
	while(cin >> n, n){
		rep(i, n) rep(j, n+1) cin >> stage[i][j];

		ans = 2<<29;
		int all = ((1<<(n+1))-1)-1;

		rep(i, n) random[i] = i+1;
		random_shuffle(random, random+n);

		dfs(all, 0);

		cout << ans << endl;
	}

	return 0;
}

Compiler output:
a.cc:20:14: error: 'int random [16]' redeclared as different kind of entity
   20 | int random[16];
      |              ^
In file included from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/c++/14/ext/string_conversions.h:43,
                 from /usr/include/c++/14/bits/basic_string.h:4154,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/stdlib.h:521:17: note: previous declaration 'long int random()'
  521 | extern long int random (void) __THROW;
      |                 ^~~~~~
a.cc: In function 'void dfs(int, int)':
a.cc:32:37: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   32 |                 if(!((rest>>random[i])&1)) continue;
      |                                     ^
a.cc:32:27: error: invalid operands of types 'int' and 'long int() noexcept' to binary 'operator>>'
   32 |                 if(!((rest>>random[i])&1)) continue;
      |                       ~~~~^~~~~~~~~~~
      |                       |             |
      |                       int           long int() noexcept
a.cc:33:46: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   33 |                 int nexttime = stage[random[i]-1][0];
      |                                              ^
a.cc:33:47: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   33 |                 int nexttime = stage[random[i]-1][0];
      |                                      ~~~~~~~~~^~
a.cc:33:37: error: invalid types 'int [16][17][long int (*)() noexcept]' for array subscript
   33 |                 int nexttime = stage[random[i]-1][0];
      |                                     ^
a.cc:36:64: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   36 |                         nexttime = min(nexttime, stage[random[i]-1][j]);
      |                                                                ^
a.cc:36:65: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   36 |                         nexttime = min(nexttime, stage[random[i]-1][j]);
      |                                                        ~~~~~~~~~^~
a.cc:36:55: error: invalid types 'int [16][17][long int (*)() noexcept]' for array subscript
   36 |                         nexttime = min(nexttime, stage[random[i]-1][j]);
      |                                                       ^
a.cc:38:40: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   38 |                 int val = ~(1<<random[i]);
      |                                        ^
a.cc:38:30: error: invalid operands of types 'int' and 'long int() noexcept' to binary 'operator<<'
   38 |                 int val = ~(1<<random[i]);
      |                             ~^~~~~~~~~~~
      |                             |          |
      |                             int        long int() noexcept
a.cc: In function 'int main()':
a.cc:51:35: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   51 |                 rep(i, n) random[i] = i+1;
      |                                   ^
a.cc:51:37: error: assignment of read-only location '*(random + ((sizetype)i))'
   51 |                 rep(i, n) random[i] = i+1;
      |                           ~~~~~~~~~~^~~~~
a.cc:52:46: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   52 |                 random_shuffle(random, random+n);
      |                                        ~~~~~~^~
a.cc:52:31: warning: 'void std::random_shuffle(_RAIter, _RAIter) [with _RAIter = long int (*)() noexcept]' is deprecated: use 'std::shuffle' instead [-Wdeprecated-declarations]
   52 |                 random_shuffle(random, random+n);
      |                 ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algo.h:4492:5: note: declared here
 4492 |     random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last)
      |     ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h: In instantiation of 'void std::random_shuffle(_RAIter, _RAIter) [with _RAIter = long int (*)() noexcept]':
a.cc:52:17:   required from here
   52 |                 random_shuffle(random, random+n);
      |                 ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4504:63: error: ISO C++ forbids using pointer to a function in subtraction [-fpermissive]
 4504 |                                         + std::rand() % ((__i - __first) + 1);
      |                                                          ~~~~~^~~~~~~~~~