Language: C++

#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif
#define LDcout(x,n) fixed<<setprecision(n)<<x

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n,m;
	while(cin>>n>>m,n){
		vvll land;
		vvll sea;
		initvv(land,n,n,INFL);
		initvv(sea,n,n,INFL);
		rep(i,m){
			int a,b,c;
			char t;
			cin>>a>>b>>c>>t;
			a--;
			b--;
			if(t=='L') land[a][b]=mins(land[b][a],c);
			else sea[a][b]=mins(sea[b][a],c);
		}
		rep(i,2) rep(j,n) land[j][j]=sea[j][j]=0;
		rep(k,n) rep(i,n) rep(j,n) mins(land[i][j],land[i][k]+land[k][j]);
		rep(k,n) rep(i,n) rep(j,n) mins(sea[i][j],sea[i][k]+sea[k][j]);
		int r;
		cin>>r;
		vint v(r);
		rep(i,r){
			cin>>v[i],v[i]--;
		}
		vll pre(n,INFL);
		pre[v[0]]=0;
		rep(i,r-1){
			vll dp(n,INFL);
			rep(k,n){
				rep(l,n){
					mins(dp[l],pre[k]+land[v[i]][k]+sea[k][l]+land[l][v[i+1]]);
				}
			}
			swap(dp,pre);
		}
		cout<< *min_element(ALL(pre))<<endl;
	}
}


signed main() {
	ios_base::sync_with_stdio(false);
    cin.tie(0);
  	cout<<fixed<<setprecision(20);
    mainmain();
}

Compiler output:
a.cc: In function 'void mainmain()':
a.cc:96:24: error: no matching function for call to 'min(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&, int&)'
   96 | #define mins(x,y) x=min(x,y)
      |                     ~~~^~~~~
a.cc:111:47: note: in expansion of macro 'mins'
  111 |                         if(t=='L') land[a][b]=mins(land[b][a],c);
      |                                               ^~~~
In file included from /usr/include/c++/14/bits/specfun.h:43,
                 from /usr/include/c++/14/cmath:3906,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:96:24: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   96 | #define mins(x,y) x=min(x,y)
      |                     ~~~^~~~~
a.cc:111:47: note: in expansion of macro 'mins'
  111 |                         if(t=='L') land[a][b]=mins(land[b][a],c);
      |                                               ^~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:10:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:96:24: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   96 | #define mins(x,y) x=min(x,y)
      |                     ~~~^~~~~
a.cc:111:47: note: in expansion of macro 'mins'
  111 |                         if(t=='L') land[a][b]=mins(land[b][a],c);
      |                                               ^~~~
a.cc:96:24: error: no matching function for call to 'min(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&, int&)'
   96 | #define mins(x,y) x=min(x,y)
      |                     ~~~^~~~~
a.cc:112:40: note: in expansion of macro 'mins'
  112 |                         else sea[a][b]=mins(sea[b][a],c);
      |                                        ^~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:96:24: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   96 | #define mins(x,y) x=min(x,y)
      |                     ~~~^~~~~
a.cc:112:40: note: in expansion of macro 'mins'
  112 |                         else sea[a][b]=mins(sea[b][a],c);
      |                                        ^~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:96:24: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   96 | #define mins(x,y) x=min(x,y)
      |                     ~~~^~~~~
a.cc:112:40: note: in expansion of macro 'mins'
  112 |                         else sea[a][b]=mins(sea[b][a],c);
      |                                        ^~~~