Language: C++

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

typedef int Weight;
struct Edge{
  int src, dest; Weight weight;
  //bool operator < (const Edge &rhs) const {return weight > rhs.weight;}
};
//(Edge){src, dest, weight}でインスタンス化できる

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

// Dijkstra (Verified: AOJ2005)
// dの要素数は頂点数と等しくあるべき．
void dijkstra(Graph &g, Array &d, int s) {
  fill(d.begin(), d.end(), INF);
  d[s] = 0;
  typedef pair<Weight,int> P;
  priority_queue<P, vector<P>, greater<P> > que;
  que.push(P(0, s));
  while (!que.empty()) {
    Weight dist = que.top().first;
    int v = que.top().second;
    que.pop();
    if (d[v] < dist) continue;
    REP(i, g[v].size()) {
      Edge e = g[v][i];
      if (d[e.dest] > d[v] + e.weight) {
        d[e.dest] = d[v] + e.weight;
        que.push(P(d[e.dest], e.dest));
      }
    }
  }
}


int uf[256];
void init(){
  REP(i,256){
    uf[i]=-1;
  }
}

int root(int i){
  if(uf[i] < 0) return i;
  return uf[i] = root(uf[i]);
}

void join(int i,int j){
  int ri=root(i);
  uf[ri]=j;
}

int main() {
  while(1){
    int n,m;
    cin>>n>>m;
    if(!n)break;
    init();
    vector<int> x(m);
    vector<int> y(m);
    vector<int> t(m);
    vector<string> sl(m);
    vector<bool> is_port(n);
    REP(i,m){
      cin>>x[i]>>y[i]>>t[i]>>sl[i];
      --x[i];--y[i];
      if(sl[i]=="L"){
        join(x[i],y[i]);
      }else{
        is_port[x[i]] = true;
        is_port[y[i]] = true;
      }
    }
    map<int,pair<int,int>> isl;
    REP(i,n){
      auto p = isl[root(i)];
      if (is_port[i])
        ++p.first;
      ++p.second;
      isl[root(i)] = p;
    }
    int isl_n = isl.size();
    map<int,int> beg_index;
    int old=-1;
    for(auto p:isl){
      auto q=p.second;
      beg_index[p.first] = q.first * q.second;
      if(old >= 0)
        beg_index[p.first] += beg_index[old];
      old = p.first;
    }
    Graph g(beg_index.back());
    Array d(beg_index.back());
    REP(i,m){
      int rx = root(x[i]);
      int ry = root(y[i]);
      int beg = beg_index[rx] - isl[rx].first * isl[rx].second;
      int ed = beg_index[ry] - isl[ry].first * isl[ry].second;
      if (sl[i] == "L") {
        REP(j,isl[rx].first) {
          int bix = beg + j*isl[rx].second + x[i];
          int eix = ed + j*isl[ry].second + y[i];
          g[bix].push_back({bix,eix,t[i]}); 
          g[eix].push_back({eix,bix,t[i]}); 
        }
      } else {
        REP(j,isl[rx].first)REP(k,isl[ry].first) {
          int bix = beg + j*isl[rx].second + x[i];
          int eix = ed + k*isl[ry].second + y[i];
          g[bix].push_back({bix,eix,t[i]});
          g[eix].push_back({eix,bix,t[i]});
        }
      }
    }
  }
  return 0;
}

Compiler output:
a.cc: In function 'void dijkstra(Graph&, Array&, int)':
a.cc:26:28: error: 'INF' was not declared in this scope
   26 |   fill(d.begin(), d.end(), INF);
      |                            ^~~
a.cc:29:3: error: 'priority_queue' was not declared in this scope
   29 |   priority_queue<P, vector<P>, greater<P> > que;
      |   ^~~~~~~~~~~~~~
a.cc:6:1: note: 'std::priority_queue' is defined in header '<queue>'; this is probably fixable by adding '#include <queue>'
    5 | #include <algorithm>
  +++ |+#include <queue>
    6 | 
a.cc:29:19: error: expected primary-expression before ',' token
   29 |   priority_queue<P, vector<P>, greater<P> > que;
      |                   ^
a.cc:29:30: error: expected primary-expression before ',' token
   29 |   priority_queue<P, vector<P>, greater<P> > que;
      |                              ^
a.cc:29:43: error: expected primary-expression before '>' token
   29 |   priority_queue<P, vector<P>, greater<P> > que;
      |                                           ^
a.cc:29:45: error: 'que' was not declared in this scope
   29 |   priority_queue<P, vector<P>, greater<P> > que;
      |                                             ^~~
a.cc: In function 'int main()':
a.cc:103:23: error: 'class std::map<int, int>' has no member named 'back'
  103 |     Graph g(beg_index.back());
      |                       ^~~~
a.cc:104:23: error: 'class std::map<int, int>' has no member named 'back'
  104 |     Array d(beg_index.back());
      |                       ^~~~