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

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define CLR(a) memset((a), 0, sizeof(a))
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

typedef long long ll;
typedef unsigned long long ull;
typedef string str;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};

int main() {
  int n, m, c, start, goal;
  while (cin >> n >> m >> c >> start >> goal, n) {
    start--;
    goal--;
    vector<vector<vector<pll>>> E(c, vector<vector<pll>>(n));
    REP(i, m) {
      int x, y, d, co;
      cin >> x >> y >> d >> co;
      x--;
      y--;
      co--;
      E[co][x].push_back({y, d});
      E[co][y].push_back({x, d});
    }
    vector<int> num(c);
    REP(i, c) { cin >> num[i]; }

    vvll cost(c, vll(n * 200, 0));
    REP(i, c) {
      vi q(num[i] - 1);
      vi r(num[i]);
      REP(j, num[i] - 1)
      cin >> q[j];
      REP(j, num[i])
      cin >> r[j];
      int qidx = 0;
      int ridx = 0;
      FOR(j, 1, n * 200) {
        cost[i][j] = cost[i][j - 1] + r[ridx];
        if (!q.empty() && qidx < q.size() && j == q[qidx]) {
          qidx++;
          ridx++;
        }
      }
    }
    vvll E2(n, vll(n, 1e9));
    REP(i, c) {
      vvll E3(n, vll(n, 1e9));
      REP(j, n)
      E3[j][j] = 0;
      REP(j, n)
      if (!E[i][j].empty())
        REP(k, E[i][j].size())
      E3[j][E[i][j][k].first] = min(E3[j][E[i][j][k].first], E[i][j][k].second);
      REP(l, n)
      REP(j, n)
      REP(k, n)
      E3[j][k] = min(E3[j][k], E3[j][l] + E3[l][k]);
      REP(j, n)
      REP(k, n)
      if (E3[j][k] != 1e9)
        E2[j][k] = min(E2[j][k], cost[i][E3[j][k]]);
    }

    REP(i, n)
    REP(j, n)
    REP(k, n)
    E2[j][k] = min(E2[j][k], E2[j][i] + E2[i][k]);
    if (E2[start][goal] == 1e9)
      cout << -1 << endl;
    else
      cout << E2[start][goal] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define CLR(a) memset((a), 0, sizeof(a))
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

typedef long long ll;
typedef unsigned long long ull;
typedef string str;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};

int main() {
  int n, m, c, start, goal;
  while (cin >> n >> m >> c >> start >> goal, n) {
    start--;
    goal--;
    vector<vector<vector<pll>>> E(c, vector<vector<pll>>(n));
    REP(i, m) {
      int x, y, d, co;
      cin >> x >> y >> d >> co;
      x--;
      y--;
      co--;
      E[co][x].push_back({y, d});
      E[co][y].push_back({x, d});
    }
    vector<int> num(n);
    REP(i, c) { cin >> num[i]; }

    vvll cost(c, vll(n * 200, 0));
    REP(i, c) {
      vi q(num[i] - 1);
      vi r(num[i]);
      REP(j, num[i] - 1)
      cin >> q[j];
      REP(j, num[i])
      cin >> r[j];
      int qidx = 0;
      int ridx = 0;
      FOR(j, 1, n * 200) {
        cost[i][j] = cost[i][j - 1] + r[ridx];
        if (!q.empty() && qidx < q.size() && j == q[qidx]) {
          qidx++;
          ridx++;
        }
      }
    }
    vvll E2(n, vll(n, 1e9));
    REP(i, c) {
      vvll E3(n, vll(n, 1e9));
      REP(j, n)
      E3[j][j] = 0;
      REP(j, n)
      if (!E[i][j].empty())
        REP(k, E[i][j].size())
      E3[j][E[i][j][k].first] = min(E3[j][E[i][j][k].first], E[i][j][k].second);
      REP(l, n)
      REP(j, n)
      REP(k, n)
      E3[j][k] = min(E3[j][k], E3[j][l] + E3[l][k]);
      REP(j, n)
      REP(k, n)
      if (E3[j][k] != 1e9)
        E2[j][k] = min(E2[j][k], cost[i][E3[j][k]]);
    }

    REP(i, n)
    REP(j, n)
    REP(k, n)
    E2[j][k] = min(E2[j][k], E2[j][i] + E2[i][k]);
    if (E2[start][goal] == 1e9)
      cout << -1 << endl;
    else
      cout << E2[start][goal] << endl;
  }

  return 0;
}