Language: C++

#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;

const double eps = 1e-12;
const double inf = (double)(1<<24);
const int size = 31;
int n, m;

class Node {
public:
  double t;
  int v, town, p;
  bool operator == ( const Node right ) const {
    return t == right.t && v == right.v && town == right.town && p == right.p;
  }
  bool operator < ( const Node right ) const {
    return fabs( t - right.t ) < eps ? v < right.v : t > right.t;
  }
  Node() {}
  Node( double t_, int v_, int town_, int p_ = -1 ) {
    t = t_;
    v = v_;
    town = town_;
    p = p_;
  }
};

// for dijkstra
typedef priority_queue <Node, vector<Node>, greater<Node> > QUEUE;
bool P[size][size]; // path
double MC[size][size]; // min cost
int D[size][size]; // distance of path
int L[size][size]; // speed limit of path
int con[size][size]; // connnect
int concnt[size];


map <int, int> T; // town number to index
int TC; // the number of towns

void reg( int town )
{
  if ( T.find( town ) != T.end() ) return;
  T[town] = TC;
  TC++;
}

void solve( int s_, int g_ )
{
  int start = T[s_], goal = T[g_];
  if ( !P[start][goal] ) {
    cout << "unreachable" << endl;
    return;
  }

  QUEUE Q;
  Node start_node( 0.0, 1, start, -1 );
  Q.push( start_node );
  MC[1][start] = 0.0;
  
  while ( !Q.empty() ) { 
    Node node = Q.top();
    Q.pop();
    double t = node.t;
    int v = node.v;
    int town = node.town;
    int prev = node.p;

    // cout << "time=" << t << ": town=" << town << ", v=" << v << endl;
    if ( town == goal && v == 1 ) {
      // cout << MC[v][town] << "," << t << endl;
      printf( "%.5f\n", t );
      return;
    }

    // cout << "test" << endl;
    for ( int i = 0; i < concnt[town]; i++ ) {
      int next_town = con[town][i];
      // debug
      // cout << town << " => " << next_town << endl;
      if ( prev != -1 && prev == next_town ) continue;
      for ( int j = -1; j < 2; j++ ) {
        if ( prev == -1 && j != 0 ) continue; 
        int next_v = v + j;
        if ( next_v <= 0 || next_v > L[town][next_town] ) continue;

        double next_t = t + (double)D[town][next_town] / next_v;
        if ( next_t + eps > MC[next_v][next_town] ) continue;

        Node next_node( next_t, next_v, next_town, town );
        MC[next_v][next_town] = next_t;
        Q.push( next_node );
      }
    }
  }
  
  cout << "unreachable" << endl;
}

int main( void )
{
  while ( cin >> n >> m && n ) {
    // init
    for ( int i = 0; i < size; i++ ) {
      T.clear();
      TC = 0;
      concnt[i] = 0;
      for ( int j = 0; j < size; j++ ) {
        P[i][j] = false;
        MC[i][j] = inf;
      }
    }

    // input
    int s, g;
    cin >> s >> g;
    for ( int i = 0; i < m; i++ ) {
      int x, y, d, c;
      cin >> x >> y >> d >> c;
      reg(x);
      reg(y);
      int xi = T[x];
      int yi = T[y];
      // cout << x << ":" << xi << ", " << y << ":" << yi << endl; // debug
      P[xi][yi] = P[yi][xi] = true;
      D[xi][yi] = D[yi][xi] = d;
      L[xi][yi] = L[yi][xi] = c;
      con[xi][concnt[xi]++] = yi;
      con[yi][concnt[yi]++] = xi;
    }

    for ( int k = 0; k < n; k++ ) {
      for ( int i = 0; i < n; i++ ) {
        for ( int j = 0; j < n; j++ ) {
          if ( !P[i][k] || !P[k][j] ) continue;
          P[i][j] = true;
        }
      }
    }

    solve( s, g );
  }

  return 0;
}

Compiler output:
a.cc:34:8: error: reference to 'size' is ambiguous
   34 | bool P[size][size]; // path
      |        ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:10:11: note:                 'const int size'
   10 | const int size = 31;
      |           ^~~~
a.cc:34:14: error: reference to 'size' is ambiguous
   34 | bool P[size][size]; // path
      |              ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:10:11: note:                 'const int size'
   10 | const int size = 31;
      |           ^~~~
a.cc:35:11: error: reference to 'size' is ambiguous
   35 | double MC[size][size]; // min cost
      |           ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:10:11: note:                 'const int size'
   10 | const int size = 31;
      |           ^~~~
a.cc:35:17: error: reference to 'size' is ambiguous
   35 | double MC[size][size]; // min cost
      |                 ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:10:11: note:                 'const int size'
   10 | const int size = 31;
      |           ^~~~
a.cc:36:7: error: reference to 'size' is ambiguous
   36 | int D[size][size]; // distance of path
      |       ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:10:11: note:                 'const int size'
   10 | const int size = 31;
      |           ^~~~
a.cc:36:13: error: reference to 'size' is ambiguous
   36 | int D[size][size]; // distance of path
      |             ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:10:11: note:                 'const int size'
   10 | const int size = 31;
      |           ^~~~
a.cc:37:7: error: reference to 'size' is ambiguous
   37 | int L[size][size]; // speed limit of path
      |       ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:10:11: note:                 'const int size'
   10 | const int size = 31;
      |           ^~~~
a.cc:37:13: error: reference to 'size' is ambiguous
   37 | int L[size][size]; // speed limit of path
      |             ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:10:11: note:                 'const int size'
   10 | const int size = 31;
      |           ^~~~
a.cc:38:9: error: reference to 'size' is ambiguous
   38 | int con[size][size]; // connnect
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:10:11: note:                 'const int size'
   10 | const int size = 31;
      |           ^~~~
a.cc:38:15: error: reference to 'size' is ambiguous
   38 | int con[size][size]; // connnect
      |               ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:10:11: note:                 'const int size'
   10 | const int size = 31;
      |           ^~~~
a.cc:39:12: error: reference to 'size' is ambiguous
   39 | int concnt[size];
      |            ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:10:11: note:                 'const int size'
   10 | const int size = 31;
      |           ^~~~
a.cc: In function 'void solve(int, int)':
a.cc:55:9: error: 'P' was not declared in this scope
   55 |   if ( !P[start][goal] ) {
      |         ^
a.cc:63:3: error: 'MC' was not declared in this scope; did you mean 'TC'?
   63 |   MC[1][start] = 0.0;
      |   ^~
      |   TC
a.cc:81:26: error: 'concnt' was not declared in this scope; did you mean 'const'?
   81 |     for ( int i = 0; i < concnt[town]; i++ ) {
      |                          ^~~~~~
      |                          const
a.cc:82:23: error: 'con' was not declared in this scope; did you mean 'cos'?
   82 |       int next_town = con[town][i];
      |                       ^~~
      |                       cos
a.cc:89:38: error: 'L' was not declared in this scope
   89 |         if ( next_v <= 0 || next_v > L[town][next_town] ) continue;
      |                                      ^
a.cc:91:37: error: 'D' was not declared in this scope
   91 |         double next_t = t + (double)D[town][next_town] / next_v;
      |                                     ^
a.cc: In function 'int main()':
a.cc:108:26: error: reference to 'size' is ambiguous
  108 |     for ( int i = 0; i < size; i++ ) {
      |                          ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:10:11: note:                 'const int size'
   10 | const int size = 31;
      |           ^~~~
a.cc:111:7: error: 'concnt' was not declared in this scope; did you mean 'const'?
  111 |       concnt[i] = 0;
      |       ^~~~~~
      |       const
a.cc:112:28: error: reference to 'size' is ambiguous
  112 |       for ( int j = 0; j < size; j++ ) {
      |                            ^~~~
/usr/include/c++/14/bits/range