Language: C++

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

typedef double Weight;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

const int M = 15;
int m[15];

vector<vector<double> > best(1<<M,vector<double>(15, INF));
Weight best[1<<M][M];
int    prev[1<<M][M];
void buildPath(int S, int i, vector<int> &path) {
  if (!S) return;
  buildPath(S^(1<<i), prev[S][i], path);
  path.push_back(i);
}
Weight shortestHamiltonPath(Matrix w, int s, vector<int> &path) {
  int n = w.size();
  int N = 1 << n;
//  REP(S,N) REP(i,n) best[S][i] = INF;
  best[1<<s][s] = 0;
  REP(S,N) {
    int we = 0;
    REP(i,n) // ツ個サツ催敖づ個重ツつウツづーツ計ツ算
      if (S&(1<<i))
        we += m[i];
    REP(i,n)
      if (S&(1<<i))
        REP(j,n) {
          if (best[S|(1<<j)][j] > best[S][i] + w[i][j] * (we + 70)) {
            best[S|(1<<j)][j] = best[S][i] + w[i][j] * (we + 70);
            prev[S|(1<<j)][j] = i;
          }
        }
  }
  int t = min_element(best[N-1], best[N-1]+n) - best[N-1]; // ツ可スツ氾板姪堋づ個陳クツ点ツづ終ツづュツづゥツづ個つェツ暗ェツ氾板短ツつュツづ按づゥツつゥ
  path.clear(); buildPath(N-1, t, path);
  return best[N-1][t];
}

int main() {
  int n;
  while(cin >> n) {
    int a[n], l[n]; 
    REP(i,n) {
      cin >> a[i] >> l[i] >> m[i];
      m[i] *= 20;
    }
    Matrix mat(n, Array(n));
    REP(i,n)
      REP(j,n)
      mat[i][j] = abs(l[j]-l[i]);
    int mi = INF;
    vector<int> path;
    REP(i,n) {
      vector<int> tpath;
      int t = shortestHamiltonPath(mat, i, tpath);
      if (t < mi) {
        path = tpath;
        mi = t;
      }
    }
    REP(i, path.size()) {
      if (i)
        cout << " ";
      cout << a[path[i]];
    }
    cout << endl;
  }
}

Compiler output:
a.cc:26:8: error: conflicting declaration 'Weight best [32768][15]'
   26 | Weight best[1<<M][M];
      |        ^~~~
a.cc:25:25: note: previous declaration as 'std::vector<std::vector<double> > best'
   25 | vector<vector<double> > best(1<<M,vector<double>(15, INF));
      |                         ^~~~
a.cc: In function 'void buildPath(int, int, std::vector<int>&)':
a.cc:30:23: error: reference to 'prev' is ambiguous
   30 |   buildPath(S^(1<<i), prev[S][i], path);
      |                       ^~~~
In file included from /usr/include/c++/14/string:47,
                 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/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:27:8: note:                 'int prev [32768][15]'
   27 | int    prev[1<<M][M];
      |        ^~~~
a.cc: In function 'Weight shortestHamiltonPath(Matrix, int, std::vector<int>&)':
a.cc:48:13: error: reference to 'prev' is ambiguous
   48 |             prev[S|(1<<j)][j] = i;
      |             ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:27:8: note:                 'int prev [32768][15]'
   27 | int    prev[1<<M][M];
      |        ^~~~
a.cc:52:43: error: no match for 'operator+' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::vector<double> >, std::vector<double> >::value_type' {aka 'std::vector<double>'} and 'int')
   52 |   int t = min_element(best[N-1], best[N-1]+n) - best[N-1]; // ツ可スツ氾板姪堋づ個陳クツ点ツづ終ツづュツづゥツづ個つェツ暗ェツ氾板短ツつュツづ按づゥツつゥ
In file included from /usr/include/c++/14/string:48:
/usr/include/c++/14/bits/stl_iterator.h:627:5: note: candidate: 'template<class _Iterator> constexpr std::reverse_iterator<_Iterator> std::operator+(typename reverse_iterator<_Iterator>::difference_type, const reverse_iterator<_Iterator>&)'
  627 |     operator+(typename reverse_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:627:5: note:   template argument deduction/substitution failed:
a.cc:52:44: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'int'
   52 |   int t = min_element(best[N-1], best[N-1]+n) - best[N-1]; // ツ可スツ氾板姪堋づ個陳クツ点ツづ終ツづュツづゥツづ個つェツ暗ェツ氾板短ツつュツづ按づゥツつゥ
      |                                            ^
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note: candidate: 'template<class _Iterator> constexpr std::move_iterator<_IteratorL> std::operator+(typename move_iterator<_IteratorL>::difference_type, const move_iterator<_IteratorL>&)'
 1798 |     operator+(typename move_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note:   template argument deduction/substitution failed:
a.cc:52:44: note:   mismatched types 'const std::move_iterator<_IteratorL>' and 'int'
   52 |   int t = min_element(best[N-1], best[N-1]+n) - best[N-1]; // ツ可スツ氾板姪堋づ個陳クツ点ツづ終ツづュツづゥツづ個つェツ暗ェツ氾板短ツつュツづ按づゥツつゥ
      |                                            ^
In file included from /usr/include/c++/14/string:54:
/usr/include/c++/14/bits/basic_string.h:3598:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3598 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3598:5: note:   template argument deduction/substitution failed:
a.cc:52:44: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<double> >, std::vector<double> >::value_type' {aka 'std::vector<double>'} is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   52 |   int t = min_element(best[N-1], best[N-1]+n) - best[N-1]; // ツ可スツ氾板姪堋づ個陳クツ点ツづ終ツづュツづゥツづ個つェツ暗ェツ氾板短ツつュツづ按づゥツつゥ
      |                                            ^
/usr/include/c++/14/bits/basic_string.h:3616:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3616 |     operator+(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3616:5: note:   template argument deduction/substitution failed:
a.cc:52:44: note:   mismatched types 'const _CharT*' and 'std::vector<double>'
   52 |   int t = min_element(best[N-1], best[N-1]+n) - best[N-1]; // ツ可スツ氾板姪堋づ個陳クツ点ツづ終ツづュツづゥツづ個つェツ暗ェツ氾板短ツつュツづ按づゥツつゥ
      |                                            ^
/usr/include/c++/14/bits/basic_string.h:3635:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3635 |     operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3635:5: note:   template argument deduction/substitution failed:
a.cc:52:44: note:   mismatched types 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and 'int'
   52 |   int t = min_element(best[N-1], best[N-1]+n) - best[N-1]; // ツ可スツ氾板姪堋づ個陳クツ点ツづ終ツづュツづゥツづ個つェツ暗ェツ氾板短ツつュツづ按づゥツつゥ
      |                                            ^
/usr/include/c++/14/bits/basic_string.h:3652:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const _CharT*)'
 3652 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3652:5: note:   template argument deduction/substitution failed:
a.cc:52:44: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<double> >, std::vector<double> >::value_type' {aka 'std::vector<double>'} is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   52 |   int t = min_element(best[N-1], best[N-1]+n) - best[N-1]; // ツ可スツ氾板姪堋づ個陳クツ点ツづ終ツづュツづゥツづ個つェツ暗ェツ氾板短ツつュツづ按づゥツつゥ
      |                                            ^
/usr/include/c++/14/bits/basic_string.h:3670:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, _CharT)'
 3670 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3670:5: note:   template argument deduction/substitution failed:
a.cc:52:44: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<double> >, std::vector<double> >::value_type' {aka 'std::vector<double>'} is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   52 |   int t = min_element(best[N-1], best[N-1]+n) - best[N-1]; // ツ可スツ氾板姪堋づ個陳クツ点ツづ終ツづュツづゥツづ個つェツ暗ェツ氾板短ツつュツづ按づゥツつゥ
      |                                            ^
/usr/include/c++/14/bits/basic_string.h:3682:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3682 |     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3682:5: note:   template argument deduction/substitution failed:
a.cc:52:44: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<double> >, std::vector<double> >::value_type' {aka 'std::vector<double>'} is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   52 |   int t = min_element(best[N-1], best[N-1]+n) - best[N-1]; // ツ可スツ氾板姪堋づ個陳クツ点ツづ終ツづュツづゥツづ個つェツ暗ェツ氾板短ツつュツづ按づゥツつゥ
      |                                            ^
/usr/include/c++/14/bits/basic_string.h:3689:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3689 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3689:5: note:   template argument deduction/substitution failed:
a.cc:52:44: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<double> >, std::vector<double> >::value_type' {aka 'std::vector<double>'} is not derived from 'const std::__cxx11::basic_stri