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

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define rep(i, x, y) for (int(i) = (x); (i) < (y); (i)++)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}

typedef long long int ll;

void solve(int n, int m, int c, int s, int g) {
  --s;
  --g;
  ll inf = 1L << 60;
  ll dist1[100][100][20];
  fill_n((ll *)dist1, 100 * 100 * 20, inf);
  rep(i, 0, n) rep(j, 0, c) dist1[i][i][j] = 0;
  vector<int> xs, ys, ds, cs;
  rep(i, 0, m) {
    int x, y, cc;
    ll d;
    cin >> x >> y >> d >> cc;
    --x;
    --y;
    --cc;
    dist1[x][y][cc] = dist1[y][x][cc] = min(dist1[x][y][cc], d);
  }
  rep(l, 0, c) rep(k, 0, n) rep(i, 0, n) rep(j, 0, n) {
    dist1[i][j][l] = min(dist1[i][j][l], dist1[i][k][l] + dist1[k][j][l]);
  }

  vector<int> p(c);
  vector<vector<ll>> q(c), r(c);
  rep(i, 0, c) cin >> p[i];
  rep(i, 0, c) {
    q[i].resize(p[i] + 1);
    r[i].resize(p[i] + 1);
    q[i].back() = inf;
    rep(j, 1, p[i]) cin >> q[i][j];
    rep(j, 1, p[i] + 1) cin >> r[i][j];
  }

  ll dist2[100][100];
  fill_n((ll *)dist2, 100 * 100, inf);
  rep(i, 0, n) dist2[i][i] = 0;

  auto f = [&](int j, ll z, int k) {
    ll sum = 0;
    rep(i, 1, k) sum += r[j][i] * (q[j][i] - q[j][i - 1]);
    sum += r[j][k] * (z - q[j][k - 1]);
    return sum;
  };
  rep(i, 0, n) rep(j, 0, n) rep(ii, 0, c) {
    ll z = dist1[i][j][ii], k;
    if (z == inf)
      continue;
    rep(l, 1, p[ii] + 1) {
      if (q[ii][l] >= z) {
        k = l;
        break;
      }
    }
    dist2[i][j] = min(dist2[i][j], f(ii, z, k));
  }

  rep(k, 0, n) rep(i, 0, n) rep(j, 0, n) {
    dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j]);
  }
  if (dist2[s][g] == inf)
    cout << -1 << endl;
  else
    cout << dist2[s][g] << endl;
}

int main() {
  while (true) {
    int n, m, c, s, g;
    cin >> n >> m >> c >> s >> g;
    if (!n and !m and !c and !s and !g)
      break;
    solve(n, m, c, s, g);
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define rep(i, x, y) for (int(i) = (x); (i) < (y); (i)++)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}

typedef long long int ll;

void solve(int n, int m, int c, int s, int g) {
  --s;
  --g;
  ll inf = 1L << 60;
  ll dist1[100][100][20];
  fill_n((ll *)dist1, 100 * 100 * 20, inf);
  vector<int> xs, ys, ds, cs;
  rep(i, 0, m) {
    int x, y, cc;
    ll d;
    cin >> x >> y >> d >> cc;
    --x;
    --y;
    --cc;
    dist1[x][y][cc] = min(dist1[x][y][cc], d);
  }
  rep(l, 0, c) rep(k, 0, n) rep(i, 0, n) rep(j, 0, n) {
    dist1[i][j][l] = min(dist1[i][j][l], dist1[i][k][l] + dist1[k][j][l]);
  }

  vector<int> p(c);
  vector<vector<int>> q(c), r(c);
  rep(i, 0, c) cin >> p[i];
  rep(i, 0, c) {
    q[i].resize(p[i] + 1);
    r[i].resize(p[i] + 1);
    q[i].back() = inf;
    rep(j, 1, p[i]) cin >> q[i][j];
    rep(j, 1, p[i] + 1) cin >> r[i][j];
  }

  ll dist2[100][100];
  fill_n((ll *)dist2, 100 * 100, inf);

  auto f = [&](int j, ll z, int k) {
    ll sum = 0;
    rep(i, 1, k) sum += r[j][i] * (q[j][i] - q[j][i - 1]);
    sum += r[j][k] * (z - q[j][k - 1]);
    return sum;
  };
  rep(i, 0, n) rep(j, 0, n) rep(ii, 0, c) {
    ll z = dist1[i][j][ii], k;
    if (z == inf)
      continue;
    rep(l, 1, p[ii] + 1) {
      if (q[ii][l] >= z) {
        k = l;
        break;
      }
    }
    dist2[i][j] = min(dist2[i][j], f(ii, z, k));
  }

  rep(k, 0, n) rep(i, 0, n) rep(j, 0, n) {
    dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j]);
  }
  if (dist2[s][g] == inf)
    cout << -1 << endl;
  else
    cout << dist2[s][g] << endl;
}

int main() {
  while (true) {
    int n, m, c, s, g;
    cin >> n >> m >> c >> s >> g;
    if (!n and !m and !c and !s and !g)
      break;
    solve(n, m, c, s, g);
  }
}