Language: C++

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define INF 0x3f3f3f3f
int map[220][220];
int r[220];
int N,M,R;

void floyd()
{
	for(int k=1;k<=N;k++)
    {
        for(int i=1;i<=N;i++)
        {
            for(int j=1;j<=N;j++)
            {
               map[i][j]=min(map[i][k]+map[k][j],map[i][j]);
            }
        }
    }
}

int main()
{
	while(~scanf("%d%d%d",&N,&M,&R))
	{
		for(int i=0;i<R;++i)
			scanf("%d",&r[i]);
		//memset(map,INF,sizeof(map));
		for(int i=0;i<=N;++i)
		{
			for(int j=0;j<=N;++j)
				if(i == j)
					map[i][j] = 0;
				else
					map[i][j] = INF;
		}
 
		for(int i=0;i<M;++i)
		{
			int x,y,z;
			scanf("%d%d%d",&x,&y,&z);
			if(map[x][y]>z || map[y][x]>z)
			{
				map[x][y]=map[y][x]=z;
			}
		}
		floyd();
		sort(R,R+r);
		int ans = INF;
		do
		{
			int sum = 0;
			for(int i=0;i<R-1;++i)
			{
				sum+=map[r[i]][r[i+1]];
			}
			ans=min(ans,sum);
		}while(next_permutation(r,r+R));
		printf("%d\n",ans);
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:51:21: error: no matching function for call to 'sort(int&, int*)'
   51 |                 sort(R,R+r);
      |                 ~~~~^~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algo.h:4762:5: note: candidate: 'template<class _RAIter> void std::sort(_RAIter, _RAIter)'
 4762 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:4762:5: note:   template argument deduction/substitution failed:
a.cc:51:21: note:   deduced conflicting types for parameter '_RAIter' ('int' and 'int*')
   51 |                 sort(R,R+r);
      |                 ~~~~^~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4793:5: note: candidate: 'template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)'
 4793 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:4793:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:292:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator, class _Compare> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _Compare)'
  292 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:292:1: note:   candidate expects 4 arguments, 2 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator)'
  296 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note:   candidate expects 3 arguments, 2 provided