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


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T> inline T sqr(T x) { return x * x; }
typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;

#define For(i, a, b) for (int(i) = (a); i < (b); (i)++)
#define rep(i, n) For(i, 0, n)
#define clr(a) memset((a), 0, sizeof(a))
#define mclr(a) memset((a), -1, sizeof(a))
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) (sizeof(a))
#define Fill(a, v) fill((int *)a, (int *)(a + (sz(a) / sz(*(a)))), v)

bool cheak(int x, int y, int xMax, int yMax) {
  return x >= 0 && y >= 0 && xMax > x && yMax > y;
}
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const int mod = 5;
const ll INF = 1e17;

const int M = 10005;
ll x[M], y[M], d[M], c[M];
ll p[22];
ll q[22][55];
ll r[22][55];
ll cD[22][105][105];
ll D[105][105];
ll cost[22][1010 * 201];
int main() {

  int n, m, C, S, G;
  while (cin >> n >> m >> C >> S >> G) {
    //??\\???????????????????????????
    if (!n && !m && !C && !S && !G)
      return 0;

    //??????????????????
    For(k, 1, C + 1) For(i, 1, n + 1) For(j, 1, n + 1) {
      cD[k][i][j] = cD[k][j][i] = (i == j ? 0 : INF);
    }
    For(i, 1, n + 1) For(j, 1, n + 1) {
      D[i][j] = D[j][i] = (i == j ? 0 : INF);
    }

    //???????????¨??????????????????????????§??????
    rep(i, m) {
      cin >> x[i] >> y[i] >> d[i] >> c[i];
      cD[c[i]][x[i]][y[i]] = cD[c[i]][y[i]][x[i]] =
          min(cD[c[i]][y[i]][x[i]], d[i]);
    }

    //???????????¨??????????????±???????????????
    For(i, 1, C + 1) cin >> p[i];
    For(i, 1, C + 1) {
      For(j, 1, p[i]) {
        cin >> q[i][j];
        q[i][j + 1] = -1;
      }
      For(j, 1, p[i] + 1) cin >> r[i][j];
    }

    //?§?????????¢??????????????????????¨????????????????
    for (int i = 1; i <= C; i++) {
      For(j, 1, p[i] + 1) {
        For(k, q[i][j - 1] + 1, q[i][j] + 1) {
          cost[i][k] = cost[i][k - 1] + r[i][j];
        }
      }
      For(k, q[i][p[i] - 1] + 1, 1010 * 201) cost[i][k] =
          cost[i][k - 1] + r[i][p[i]];
    }

    //???????????¨??????????????£?????????????????????
    For(l, 1, C + 1) {
      For(k, 1, n + 1) For(i, 1, n + 1) For(j, 1, n + 1) {
        cD[l][j][i] = cD[l][i][j] = min(cD[l][i][j], cD[l][i][k] + cD[l][k][j]);
      }
    }
    For(i, 1, n + 1) For(j, 1, n + 1) For(k, 1, C + 1) {
      if (cD[k][i][j] != INF) {
        D[i][j] = D[j][i] = min(D[i][j], cost[k][cD[k][i][j]]);
      }
    }
    For(k, 1, n + 1) For(i, 1, n + 1) For(j, 1, n + 1) {
      D[j][i] = D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
    }
    if (D[S][G] == INF)
      D[S][G] = -1;
    cout << D[S][G] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T> inline T sqr(T x) { return x * x; }
typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;

#define For(i, a, b) for (int(i) = (a); i < (b); (i)++)
#define rep(i, n) For(i, 0, n)
#define clr(a) memset((a), 0, sizeof(a))
#define mclr(a) memset((a), -1, sizeof(a))
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) (sizeof(a))
#define Fill(a, v) fill((int *)a, (int *)(a + (sz(a) / sz(*(a)))), v)

bool cheak(int x, int y, int xMax, int yMax) {
  return x >= 0 && y >= 0 && xMax > x && yMax > y;
}
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const int mod = 5;
const ll INF = 1e17;

const int M = 10005;
ll x[M], y[M], d[M], c[M];
ll p[22];
ll q[22][55];
ll r[22][55];
ll cD[22][105][105];
ll D[105][105];
ll cost[22][1010 * 201];
int main() {

  int n, m, C, S, G;
  while (cin >> n >> m >> C >> S >> G) {
    if (!n && !m && !C && !S && !G)
      return 0;
    For(k, 1, C + 1) For(i, 1, n + 1) For(j, 1, n + 1) {
      cD[k][i][j] = cD[k][j][i] = (i == j ? 0 : INF);
    }
    rep(i, m) {
      cin >> x[i] >> y[i] >> d[i] >> c[i];
      cD[c[i]][x[i]][y[i]] = cD[c[i]][y[i]][x[i]] =
          min(cD[c[i]][y[i]][x[i]], d[i]);
    }
    rep(i, C) cin >> p[i];
    rep(i, C) {
      rep(j, p[i] - 1) cin >> q[i][j];
      rep(j, p[i]) cin >> r[i][j];
    }

    for (int i = 1; i <= C; i++) {
      int t = 0;
      cost[i][1] = r[i - 1][t];
      if (1 == q[i - 1][t])
        t++;
      for (int j = 2; j < 10001 * 201; j++) {
        cost[i][j] = cost[i][j - 1] + r[i - 1][t];
        if (j == q[i - 1][t])
          t++;
      }
    }
    For(l, 1, C + 1) {
      For(k, 1, n + 1) For(i, 1, n + 1) For(j, 1, n + 1) {
        cD[l][j][i] = cD[l][i][j] = min(cD[l][i][j], cD[l][i][k] + cD[l][k][j]);
      }
    }
    For(i, 1, n + 1) For(j, 1, n + 1) {
      D[i][j] = D[j][i] = (i == j ? 0 : INF);
    }
    For(i, 1, n + 1) For(j, 1, n + 1) For(k, 1, C + 1) {
      if (cD[k][i][j] != INF) {
        D[i][j] = D[j][i] = min(D[i][j], cost[k][cD[k][i][j]]);
      }
    }
    For(k, 1, n + 1) For(i, 1, n + 1) For(j, 1, n + 1) {
      D[j][i] = D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
    }
    if (D[S][G] == INF)
      D[S][G] = -1;
    cout << D[S][G] << endl;
  }
  return 0;
}