Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<functional>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define INF INT_MAX/2
#define ll long long

int dist[21][101][101];
int ddist[101][101];
int p[21];
int q[21][51];
int r[21][51];

int getCost(int c, int d) {
	if (p[c] == 1 || d <= q[c][0]) return d * r[c][0];
	
	int fare = 0;
	int i = 0;
	while (q[c][i] < d)
	{
		if (i == 0) fare += q[c][0] * r[c][0];
		else fare += (q[c][i] - q[c][i - 1]) * r[c][i];

		i++;
		if (i == p[c] - 1) {
			fare += (d - q[c][i - 1]) * r[c][i];
			return fare;
		}
	}

	fare += (d - q[c][i - 1]) * r[c][i];
	return fare;
}

int main()
{
	int n, m, c, s, g;
	while (cin >> n >> m >> c >> s >> g, n || m || c || s || g) {
		s--;
		g--;
		
		REP(i, 0, c) REP(j, 0, n) REP(k, 0, n) {
			if (j == k) dist[i][j][k] = 0;
			else dist[i][j][k] = INF;
		}
		REP(i, 0, n) REP(j, 0, n) {
			if (i == j) ddist[i][j] = 0;
			else ddist[i][j] = INF;
		}
		REP(i, 0, m) {
			int x, y, d, c;
			cin >> x >> y >> d >> c;
			x--;
			y--;
			c--;
			dist[c][x][y] = min(dist[c][x][y], d);
			dist[c][y][x] = min(dist[c][y][x], d);
		}
		REP(i, 0, c) cin >> p[i];
		REP(i, 0, c) {
			REP(j, 0, p[i] - 1) cin >> q[i][j];
			REP(j, 0, p[i] ) cin >> r[i][j];
		}

		REP(num, 0, c) REP(i, 0, n) REP(j, 0, n) REP(k, 0, n) {
			dist[num][j][k] = min(dist[num][j][k], dist[num][j][i] + dist[num][i][k]);
		}

		REP(num, 0, c) REP(i, 0, n) REP(j, 0, n) {
			if (dist[c][i][j] == INF) continue;
			int cost = getCost(num, dist[num][i][j]);

			ddist[i][j] = min(ddist[i][j], cost);
		}

		REP(i, 0, n) REP(j, 0, n) REP(k, 0, n) {
			ddist[j][k] = min(ddist[j][k], ddist[j][i] + ddist[i][k]);
		}

		if (ddist[s][g] == INF) cout << -1 << endl;
		else cout << ddist[s][g] << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:13: error: 'INT_MAX' was not declared in this scope
    9 | #define INF INT_MAX/2
      |             ^~~~~~~
a.cc:48:46: note: in expansion of macro 'INF'
   48 |                         else dist[i][j][k] = INF;
      |                                              ^~~
a.cc:7:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    6 | #include<functional>
  +++ |+#include <climits>
    7 | using namespace std;
a.cc:9:13: error: 'INT_MAX' was not declared in this scope
    9 | #define INF INT_MAX/2
      |             ^~~~~~~
a.cc:52:44: note: in expansion of macro 'INF'
   52 |                         else ddist[i][j] = INF;
      |                                            ^~~
a.cc:9:13: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    9 | #define INF INT_MAX/2
      |             ^~~~~~~
a.cc:52:44: note: in expansion of macro 'INF'
   52 |                         else ddist[i][j] = INF;
      |                                            ^~~
a.cc:9:13: error: 'INT_MAX' was not declared in this scope
    9 | #define INF INT_MAX/2
      |             ^~~~~~~
a.cc:74:46: note: in expansion of macro 'INF'
   74 |                         if (dist[c][i][j] == INF) continue;
      |                                              ^~~
a.cc:9:13: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    9 | #define INF INT_MAX/2
      |             ^~~~~~~
a.cc:74:46: note: in expansion of macro 'INF'
   74 |                         if (dist[c][i][j] == INF) continue;
      |                                              ^~~
a.cc:9:13: error: 'INT_MAX' was not declared in this scope
    9 | #define INF INT_MAX/2
      |             ^~~~~~~
a.cc:84:36: note: in expansion of macro 'INF'
   84 |                 if (ddist[s][g] == INF) cout << -1 << endl;
      |                                    ^~~
a.cc:9:13: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    9 | #define INF INT_MAX/2
      |             ^~~~~~~
a.cc:84:36: note: in expansion of macro 'INF'
   84 |                 if (ddist[s][g] == INF) cout << -1 << endl;
      |                                    ^~~