Language: C++

#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <cstdio>
#include <cmath>
#include <utility>
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
using namespace std;
const int inf=(int)1e9;
const double PI=acos(-1.0);
  
  
  
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;
    int n,m;
    while(cin>>n>>m,n){
        ll land[201][201],sea[201][201];
    int a[1001];
    for(int i=0;i<201;i++){
      for(int j=0;j<201;j++){
        land[i][j]=inf;
        sea[i][j]=inf;
      }
    }
    for(int i=0;i<201;i++){
      land[i][i]=0;
      sea[i][i]=0;
    }
    for(int i=0;i<m;i++){
      int x,y;ll t;
      char sl;
      cin>>x>>y>>t>>sl;
      x--;y--;
      if(sl=='S'){
        sea[x][y]=min(sea[x][y],t);
        sea[y][x]=min(sea[x][y],t);
      }else{
        land[x][y]=min(sea[x][y],t);
        land[y][x]=min(sea[x][y],t);
      }
    }
        for(int k=0;k<n;k++){
            for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                    ldp[i][j]=min(ldp[i][k]+ldp[k][j],ldp[i][j]);
                    sdp[i][j]=min(sdp[i][k]+sdp[k][j],sdp[i][j]);
                }
            }
        }
        int r;cin>>r;
        int a[1001];
        for(int i=0;i<r;i++){
            cin>>a[i];
            a[i]--;
        }
        int dp[1001][201];
        for(int i=0;i<1001;i++)for(int j=0;j<201;j++)dp[i][j]=inf;
        dp[0][a[0]]=0;
        for(int i=0;i<r-1;i++){
            for(int j=0;j<n;j++){
                if(dp[i][j]==inf)continue;
                for(int k=0;k<n;k++){
                    dp[i+1][k]=min(dp[i+1][k],dp[i][j]+ldp[a[i]][j]+sdp[j][k]+ldp[k][a[i+1]]);
                    if(j==k)dp[i+1][k]=min(dp[i+1][k],dp[i][j]+ldp[a[i]][a[i+1]]);
                }
            }
        }
        /*for(int i=0;i<r;i++){
            for(int j=0;j<n;j++){
                cerr<<dp[i][j]<<" ";
            }
            cerr<<"\n";
        }*/
        int ans=inf;
        for(int i=0;i<n;i++){
            ans=min(ans,dp[r-1][i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:65:21: error: 'ldp' was not declared in this scope
   65 |                     ldp[i][j]=min(ldp[i][k]+ldp[k][j],ldp[i][j]);
      |                     ^~~
a.cc:66:21: error: 'sdp' was not declared in this scope
   66 |                     sdp[i][j]=min(sdp[i][k]+sdp[k][j],sdp[i][j]);
      |                     ^~~
a.cc:71:13: error: redeclaration of 'int a [1001]'
   71 |         int a[1001];
      |             ^
a.cc:38:9: note: 'int a [1001]' previously declared here
   38 |     int a[1001];
      |         ^
a.cc:83:56: error: 'ldp' was not declared in this scope; did you mean 'dp'?
   83 |                     dp[i+1][k]=min(dp[i+1][k],dp[i][j]+ldp[a[i]][j]+sdp[j][k]+ldp[k][a[i+1]]);
      |                                                        ^~~
      |                                                        dp
a.cc:83:69: error: 'sdp' was not declared in this scope; did you mean 'dp'?
   83 |                     dp[i+1][k]=min(dp[i+1][k],dp[i][j]+ldp[a[i]][j]+sdp[j][k]+ldp[k][a[i+1]]);
      |                                                                     ^~~
      |                                                                     dp