Language: C++

#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <list>
#include <cstring>
#include <stack>
   
using namespace std;

#define mod 1000000007

int n, m, s, g;

double solve(pair<double, double> r[31][31])
{
    double result[31][31][31];
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            for(int k = 1; k <= 31; k++){
                result[i][j][k] = mod;
            }
        }
    }
    priority_queue<pair<double, pair<pair<int, int>, int> > > qu;
    qu.push(make_pair(0.0, make_pair(make_pair(s, -1), 0.0)));
    while(!qu.empty()){
        double nowcost = (qu.top()).first;
        pair<int, int> nowandbefore = ((qu.top()).second).first;
        int nowv = ((qu.top()).second).second;
        int nowp = nowandbefore.first;
        int beforep = nowandbefore.second;
        // cout << nowp << " " << beforep << " " << -nowcost << " " << nowv << endl;
        qu.pop();
        if(nowp == g && nowv == 1) {
            return -nowcost;
        }
        if(beforep != -1 && result[nowp][beforep][nowv] < -nowcost) continue;
        result[nowp][beforep][nowv] = -nowcost;
        for(int i = 1; i <= n; i++){
            if(r[nowp][i].first == 0 || i == beforep) continue;
            double kyori = r[nowp][i].first;
            double limit = r[nowp][i].second;
            double nextcost;
            for(int j = -1; j <= 1; j++){
                if(nowv + j <= 0) continue;
                nextcost = nowcost - (double)kyori / (nowv + j);
                if(nowv + j <= limit && -nextcost < result[i][nowp][nowv + j]){
                    result[i][nowp][nowv + j] = -nextcost;
                    qu.push(make_pair(nextcost, make_pair(make_pair(i, nowp), nowv + j)));
                }
            }
        }
    }
    return -1;
}

int main()
{
    while(1){
        cin >> n >> m;
        if(n == 0) break;
        cin >> s >> g;
        pair<double, double> road[31][31];
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                road[i][j] = make_pair(0, 0);
            }
        }
        for(int i = 0; i < m; i++){
            int x, y;
            double d, c;
            cin >> x >> y >> d >> c;
            road[x][y] = road[y][x] = make_pair(d, c);
        }
        double ans =  solve(road);
        if(ans == -1) cout << "unreachable" << endl;
        else cout << ans << endl;
    }
    return 0;
}#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <list>
#include <cstring>
#include <stack>
   
using namespace std;

#define mod 1000000007

int n, m, s, g;

double solve(pair<double, double> r[31][31])
{
    double result[31][31][31];
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            for(int k = 1; k <= 31; k++){
                result[i][j][k] = mod;
            }
        }
    }
    priority_queue<pair<double, pair<pair<int, int>, int> > > qu;
    qu.push(make_pair(0.0, make_pair(make_pair(s, -1), 0.0)));
    while(!qu.empty()){
        double nowcost = (qu.top()).first;
        pair<int, int> nowandbefore = ((qu.top()).second).first;
        int nowv = ((qu.top()).second).second;
        int nowp = nowandbefore.first;
        int beforep = nowandbefore.second;
        // cout << nowp << " " << beforep << " " << -nowcost << " " << nowv << endl;
        qu.pop();
        if(nowp == g && nowv == 1) {
            return -nowcost;
        }
        if(beforep != -1 && result[nowp][beforep][nowv] < -nowcost) continue;
        result[nowp][beforep][nowv] = -nowcost;
        for(int i = 1; i <= n; i++){
            if(r[nowp][i].first == 0 || i == beforep) continue;
            double kyori = r[nowp][i].first;
            double limit = r[nowp][i].second;
            double nextcost;
            for(int j = -1; j <= 1; j++){
                if(nowv + j <= 0) continue;
                nextcost = nowcost - (double)kyori / (nowv + j);
                if(nowv + j <= limit && -nextcost < result[i][nowp][nowv + j]){
                    result[i][nowp][nowv + j] = -nextcost;
                    qu.push(make_pair(nextcost, make_pair(make_pair(i, nowp), nowv + j)));
                }
            }
        }
    }
    return -1;
}

int main()
{
    while(1){
        cin >> n >> m;
        if(n == 0) break;
        cin >> s >> g;
        pair<double, double> road[31][31];
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                road[i][j] = make_pair(0, 0);
            }
        }
        for(int i = 0; i < m; i++){
            int x, y;
            double d, c;
            cin >> x >> y >> d >> c;
            road[x][y] = road[y][x] = make_pair(d, c);
        }
        double ans =  solve(road);
        if(ans == -1) cout << "unreachable" << endl;
        else cout << ans << endl;
    }
    return 0;
}

Compiler output:
a.cc:91:2: error: stray '#' in program
   91 | }#include <cstdio>
      |  ^
a.cc:91:3: error: 'include' does not name a type
   91 | }#include <cstdio>
      |   ^~~~~~~
a.cc:113:5: error: redefinition of 'int n'
  113 | int n, m, s, g;
      |     ^
a.cc:23:5: note: 'int n' previously declared here
   23 | int n, m, s, g;
      |     ^
a.cc:113:8: error: redefinition of 'int m'
  113 | int n, m, s, g;
      |        ^
a.cc:23:8: note: 'int m' previously declared here
   23 | int n, m, s, g;
      |        ^
a.cc:113:11: error: redefinition of 'int s'
  113 | int n, m, s, g;
      |           ^
a.cc:23:11: note: 'int s' previously declared here
   23 | int n, m, s, g;
      |           ^
a.cc:113:14: error: redefinition of 'int g'
  113 | int n, m, s, g;
      |              ^
a.cc:23:14: note: 'int g' previously declared here
   23 | int n, m, s, g;
      |              ^
a.cc:115:8: error: redefinition of 'double solve(std::pair<double, double> (*)[31])'
  115 | double solve(pair<double, double> r[31][31])
      |        ^~~~~
a.cc:25:8: note: 'double solve(std::pair<double, double> (*)[31])' previously defined here
   25 | double solve(pair<double, double> r[31][31])
      |        ^~~~~
a.cc:158:5: error: redefinition of 'int main()'
  158 | int main()
      |     ^~~~
a.cc:68:5: note: 'int main()' previously defined here
   68 | int main()
      |     ^~~~