Problem p00763 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define X first
#define Y second
#define pb push_back
#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define rrep(X, Y) for (int(X) = (Y - 1); (X) >= 0; --(X))
#define repe(X, Y) for ((X) = 0; (X) < (Y); ++(X))
#define peat(X, Y) for (; (X) < (Y); ++(X))
#define all(X) (X).begin(), (X).end()
#define rall(X) (X).rbegin(), (X).rend()
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef ll Cost;
struct Edge {
  int to, cap, rev;
  Cost cost;
};
typedef vector<Edge> Edges;
typedef vector<vector<Edge>> Graph;
typedef pair<Cost, int> Que;

void add_edge(Graph &g, int from, int to, int cap, Cost cost = 0) {
  g[from].pb((Edge){to, cap, (int)g[to].size(), cost});
  //  g[to].pb((Edge){from,0,(int)g[from].size()-1,-cost});
}
Cost INF = 5e15;
// dij

void dij(Graph &g, int s, vector<Cost> &d) {
  priority_queue<Que, vector<Que>, greater<Que>> que;
  int V = g.size();
  d.resize(V);
  fill(all(d), INF);
  d[s] = 0;
  que.push(Que(0, s));
  while (!que.empty()) {
    Que p = que.top();
    que.pop();
    int v = p.Y;
    if (d[v] < p.X)
      continue;
    for (int i = 0; i < g[v].size(); i++) {
      Edge e = g[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(Que(d[e.to], e.to));
      }
    }
  }
}
Cost d[25][112][112];

int main() {
  int n, m, c, s, dst;
  while (cin >> n >> m >> c >> s >> dst) {
    if (!n)
      break;
    --s;
    --dst;
    fill(d[0][0], d[0][0] + 25 * 112 * 112, INF);
    rep(i, c) rep(j, n) d[i][j][j] = 0;
    ll x, y, d_, t;
    rep(i, m) {
      cin >> x >> y >> d_ >> t;
      --x;
      --y;
      --t;
      d[t][x][y] = d[t][y][x] = min(d[t][y][x], d_);
    }
    if (0)
      rep(i, c) {
        rep(j, n) {
          rep(k, n) cout << d[i][j][k] << ",";
          cout << endl;
        }
        cout << endl;
      }
    rep(t, c) rep(k, n) rep(i, n) rep(j, n) d[t][i][j] =
        min(d[t][i][j], d[t][i][k] + d[t][k][j]);
    if (0)
      rep(i, c) {
        rep(j, n) {
          rep(k, n) cout << d[i][j][k] << ",";
          cout << endl;
        }
        cout << endl;
      }

    vector<vector<ll>> p(c), r(c), sum(c);
    rep(i, c) {
      cin >> t;
      p[i].resize(t);
      r[i].resize(t);
      sum[i].resize(t);
    }
    rep(i, c) {
      rep(j, p[i].size()) if (j) cin >> p[i][j];
      rep(j, r[i].size()) cin >> r[i][j];
      // rep(j,r[i].size())cout<<r[i][j]<<" ";cout<<endl;
      rep(j, r[i].size() - 1) sum[i][j + 1] =
          sum[i][j] + (p[i][j + 1] - p[i][j]) * r[i][j];
      // rep(j,r[i].size())cout<<sum[i][j]<<" ";cout<<endl;
    }
    Graph g(n);
    rep(i, c) rep(j, n) rep(k, j) {
      //    cout<<d[i][j][k]<<endl;
      if (d[i][j][k] != INF) {
        int t = upper_bound(all(p[i]), d[i][j][k]) - p[i].begin() - 1;
        ll cost = sum[i][t] + (d[i][j][k] - p[i][t]) * r[i][t];
        // cout<<i<<","<<d[i][j][k]<<":"<<cost<<","<<p[i][t]<<","<<r[i][t]<<endl;
        add_edge(g, k, j, 0, cost);
        add_edge(g, j, k, 0, cost);
      }
    }
    vector<Cost> re;
    dij(g, s, re);
    cout << (re[dst] == INF ? -1 : re[dst]) << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define X first
#define Y second
#define pb push_back
#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define rrep(X, Y) for (int(X) = (Y - 1); (X) >= 0; --(X))
#define repe(X, Y) for ((X) = 0; (X) < (Y); ++(X))
#define peat(X, Y) for (; (X) < (Y); ++(X))
#define all(X) (X).begin(), (X).end()
#define rall(X) (X).rbegin(), (X).rend()
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef ll Cost;
struct Edge {
  int to, cap, rev;
  Cost cost;
};
typedef vector<Edge> Edges;
typedef vector<vector<Edge>> Graph;
typedef pair<Cost, int> Que;

void add_edge(Graph &g, int from, int to, int cap, Cost cost = 0) {
  g[from].pb((Edge){to, cap, (int)g[to].size(), cost});
  //  g[to].pb((Edge){from,0,(int)g[from].size()-1,-cost});
}
Cost INF = 5e15;
// dij

void dij(Graph &g, int s, vector<Cost> &d) {
  priority_queue<Que, vector<Que>, greater<Que>> que;
  int V = g.size();
  d.resize(V);
  fill(all(d), INF);
  d[s] = 0;
  que.push(Que(0, s));
  while (!que.empty()) {
    Que p = que.top();
    que.pop();
    int v = p.Y;
    if (d[v] < p.X)
      continue;
    for (int i = 0; i < g[v].size(); i++) {
      Edge e = g[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(Que(d[e.to], e.to));
      }
    }
  }
}

int main() {
  int n, m, c, s, dst;
  while (cin >> n >> m >> c >> s >> dst) {
    if (!n)
      break;
    --s;
    --dst;
    Cost d[c][n][n];
    fill(d[0][0], d[0][0] + c * n * n, INF);
    rep(i, c) rep(j, n) d[i][j][j] = 0;
    ll x, y, d_, t;
    rep(i, m) {
      cin >> x >> y >> d_ >> t;
      --x;
      --y;
      --t;
      d[t][x][y] = d[t][y][x] = min(d[t][y][x], d_);
    }
    if (0)
      rep(i, c) {
        rep(j, n) {
          rep(k, n) cout << d[i][j][k] << ",";
          cout << endl;
        }
        cout << endl;
      }
    rep(t, c) rep(k, n) rep(i, n) rep(j, n) d[t][i][j] =
        min(d[t][i][j], d[t][i][k] + d[t][k][j]);
    if (0)
      rep(i, c) {
        rep(j, n) {
          rep(k, n) cout << d[i][j][k] << ",";
          cout << endl;
        }
        cout << endl;
      }

    vector<vector<ll>> p(n), r(n), sum(n);
    rep(i, c) {
      cin >> t;
      p[i].resize(t);
      r[i].resize(t);
      sum[i].resize(t);
    }
    rep(i, c) {
      rep(j, p[i].size()) if (j) cin >> p[i][j];
      rep(j, r[i].size()) cin >> r[i][j];
      // rep(j,r[i].size())cout<<r[i][j]<<" ";cout<<endl;
      rep(j, r[i].size() - 1) sum[i][j + 1] =
          sum[i][j] + (p[i][j + 1] - p[i][j]) * r[i][j];
      // rep(j,r[i].size())cout<<sum[i][j]<<" ";cout<<endl;
    }
    Graph g(n);
    rep(i, c) rep(j, n) rep(k, j) {
      //    cout<<d[i][j][k]<<endl;
      if (d[i][j][k] != INF) {
        int t = upper_bound(all(p[i]), d[i][j][k]) - p[i].begin() - 1;
        ll cost = sum[i][t] + (d[i][j][k] - p[i][t]) * r[i][t];
        // cout<<i<<","<<d[i][j][k]<<":"<<cost<<","<<p[i][t]<<","<<r[i][t]<<endl;
        add_edge(g, k, j, 0, cost);
        add_edge(g, j, k, 0, cost);
      }
    }
    vector<Cost> re;
    dij(g, s, re);
    cout << (re[dst] == INF ? -1 : re[dst]) << endl;
  }
}