Language: C++

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;

typedef vector<bool> VB;
typedef vector<VB> VVB;

#define fst first;
#define snd second;
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) (x).begin(), (x).end()
#define RANGE(x, y, w, h) (0 <= (x) && 0 <= (y) && (x) < (w) && (y) < (h))
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for (int i = (init); i < (n); i++)

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const int DX[] = {1,0,-1,0}, DY[] = {0,-1,0,1};

int N, M;
int R;
VI rs;

VVI seas;
VVI loads;

int solve() {
    // ????????????
    rep(k, N) {
        rep(i, N) {
            rep(j, N) {
                seas[i][j] = min(seas[i][j], seas[i][k] + seas[k][j]);
                loads[i][j] = min(loads[i][j], loads[i][k] + loads[k][j]);
            }
        }
    }
    // 8,000,000

    cout << "????????????ok!" << endl;

    // dp[ri][where]
    VVI dp(R, VI(V));
    dp[0][R[0]] = 0;

    rep(ri, R - 1) {    // 1000
        rep(w, V) {     // 200
            if (dp[ri][w] == INF) continue;

            int s = R[ri];
            int g = R[ri + 1];

            dp[ri + 1][w] = min(dp[ri + 1][w], dp[ri][w] + loads[s][g]);

            int cost = dp[ri][w] + loads[s][w];
            rep(w2, V) {    // 200
                int cost2 = cost;
                cost2 += seas[w][w2];
                cost2 += loads[w2][g];
                dp[ri + 1][w2] = min(dp[ri + 1][w2], cost2);
            }
        }
    }
    // 40,000,000


    return *min_element(ALL(dp[R.back()]));
}

int main(void) {
    cin.tie( 0 );
    ios::sync_with_stdio( false );

    while (cin >> N >> M, N) {
        es.clear();
        es.resize(N);

        seas = VVI(N, VI(N, INF));
        loads = VVI(N, VI(N, INF));
        rep(i, N) rep(j, N) {
            seas[i][j] = 0;
            loads[i][j] = 0;
        }

        rep(i, M) {
            int x, y, t;
            char sl;
            cin >> x >> y >> t >> sl;
            --x; --y;

            bool is_sea = sl == 'S';

            (is_sea ? seas : loads)[x][y] = t;
            (is_sea ? seas : loads)[y][x] = t;
        }

        cin >> R;
        rs = VI(R);
        for (auto &r : rs) {
            cin >> r;
            --r;
        }

        cout << solve() << endl;
    }

    return 0;
}

Compiler output:
a.cc: In function 'int solve()':
a.cc:49:18: error: 'V' was not declared in this scope; did you mean 'VI'?
   49 |     VVI dp(R, VI(V));
      |                  ^
      |                  VI
a.cc:50:12: error: invalid types 'int[int]' for array subscript
   50 |     dp[0][R[0]] = 0;
      |            ^
a.cc:56:22: error: invalid types 'int[int]' for array subscript
   56 |             int s = R[ri];
      |                      ^
a.cc:57:22: error: invalid types 'int[int]' for array subscript
   57 |             int g = R[ri + 1];
      |                      ^
a.cc:73:34: error: request for member 'back' in 'R', which is of non-class type 'int'
   73 |     return *min_element(ALL(dp[R.back()]));
      |                                  ^~~~
a.cc:18:17: note: in definition of macro 'ALL'
   18 | #define ALL(x) (x).begin(), (x).end()
      |                 ^
a.cc:73:34: error: request for member 'back' in 'R', which is of non-class type 'int'
   73 |     return *min_element(ALL(dp[R.back()]));
      |                                  ^~~~
a.cc:18:30: note: in definition of macro 'ALL'
   18 | #define ALL(x) (x).begin(), (x).end()
      |                              ^
a.cc: In function 'int main()':
a.cc:81:9: error: 'es' was not declared in this scope; did you mean 'rs'?
   81 |         es.clear();
      |         ^~
      |         rs