Language: C++

#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl
#define printVS(vs) for(auto x : vs){cout << x << endl;}
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto p : vp) printP(p);
#define readV(_v) rep(j, _v.size()) cin >> _v[j];
#define readVV(_vv) rep(i, _vv.size()) readV(_vv[i]);
#define output(_x) cout << _x << endl;

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

class WarshallFloyd {
private:
    const int n;
    vector<vector<int>> d;
public:
    WarshallFloyd(int _n) : n(_n), d(_n, vector<int>(_n)) {
        rep(i, n) rep(j, n) {
            d[i][j] = (i == j ? 0 : inf);
        }
    }
    // undirected
    void setDist(int i, int j, int c) {
        d[i][j] = c;
        d[j][i] = c;
    }
    int getDist(int i, int j) {
        return d[i][j];
    }
    void calc() {
        rep(k, n) rep(i, n) rep(j, n) {
            d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
    }
};

struct edge {
    int to, cost;
    edge(){}
    edge(int _to, int _cost) : to(_to), cost(_cost) {}
    print() {
        cout << to << " " << cost << endl;
    }
};
typedef vector<vector<edge>> Graph;

// undirected
void addEdge(Graph& G, int x, int y, int d) {
    G[x].emplace_back(y, d);
    G[y].emplace_back(x, d);
}

int dijkstra(const Graph& G, int s, int g) {
    int n = G.size();
    priority_queue<Pii, vector<Pii>, greater<Pii>> pq;   // cost, vertex
    vi d(n, inf);
    d[s] = 0;
    pq.push(make_pair(0, s));

    while (!pq.empty()) {
        auto p = pq.top(); pq.pop();
        int v = p.second;
        if (v == g) break;
        if (d[v] < p.first) continue;
        for (const auto& e : G[v]) {
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                pq.push(make_pair(d[e.to], e.to));
            }
        }
    }
    return d[g];
}

struct Query {
    int x, y, d, c;
    Query(){}
    Query(int _x, int _y, int _d, int _c) : x(_x), y(_y), d(_d), c(_c) {}
    void print() {
        cout << x << " " << y << " " << d << " " << c << endl;
    }
};

void printGraph(const Graph& G) {
    rep(i, G.size()) {
        cout << i << ": ";
        rep(j, G[i].size()) {
            cout << "{" << G[i][j].to << ", " << G[i][j].cost << "}, ";
        }
        cout << endl;
    }
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int n, m, C, s, g;
    int testcase = 0;
    while (cin >> n >> m >> C >> s >> g, n) {
        s--; g--;
        // cout << "--- testcase " << testcase << " ---" << endl;
        vector<Query> queries;
        rep(i, m) {
            int x, y, d, c;
            cin >> x >> y >> d >> c;
            x--; y--; c--;
            queries.emplace_back(x, y, d, c);
        }
        vi p(C);
        rep(i, C) cin >> p[i];
        vvi q(C), r(C);
        rep(i, C) {
            q[i].resize(p[i] + 1);
            q[i][0] = 0;
            rep(j, p[i] - 1) cin >> q[i][j + 1];
            q[i].back() = inf;

            r[i].resize(p[i]);
            rep(j, p[i]) cin >> r[i][j];
        }

        // cout << "queries:" << endl;
        // rep(i, m) {
        //     queries[i].print();
        // }
        // cout << "p:" << endl;
        // printV(p);
        // cout << "q:" << endl;
        // printVV(q);
        // cout << "r:" << endl;
        // printVV(r);

        auto Cost = [&](int d, int c){
            int cost = 0;
            rep(j, (int)q[c].size() - 1) {
                if (d < q[c][j + 1]) {
                    cost += (d - q[c][j]) * r[c][j];
                    return cost;
                } else {
                    cost += (q[c][j + 1] - q[c][j]) * r[c][j];
                }
            }
            assert(false);
        };

        Graph G(n);
        rep(c, C) {
            WarshallFloyd wf(n);
            for (auto query : queries) {
                if (query.c == c) {
                    wf.setDist(query.x, query.y, query.d);
                }
            }

            wf.calc();

            rep(i, n) {
                rep2(j, i + 1, n) {
                    int d = wf.getDist(i, j);
                    if (0 < d && d < inf) {
                        addEdge(G, i, j, Cost(d, c));
                    }
                }
            }
            // cout << "c = " << c << endl;
            // printGraph(G);

        }

        // cout << "ans:" << endl;
        int ans = dijkstra(G, s, g);
        cout << (ans < inf ? ans : -1) << endl;
        // cerr << "hey!" << endl;
    }

}

Compiler output:
a.cc:59:5: error: ISO C++ forbids declaration of 'print' with no type [-fpermissive]
   59 |     print() {
      |     ^~~~~
a.cc: In member function 'int edge::print()':
a.cc:61:5: warning: no return statement in function returning non-void [-Wreturn-type]
   61 |     }
      |     ^