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

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define fi first
#define se second
#define repl(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX / 3
#define mod 1000000007

struct state {
  int v, r, d;
};

bool operator<(const state &a, const state &b) { return a.d > b.d; }

int n, m, C;
string src, dst;
int S, T;
map<string, int> idx;
vector<P> g[6000];
bool aru[6000];
int dist[6000][2010];
int V = 0;

int getidx(string s) {
  if (idx.find(s) != idx.end())
    return idx[s];
  idx[s] = V++;
  return idx[s];
}

int main() {
  while (1) {
    cin >> m >> n >> C;
    if (m == 0 && n == 0)
      break;

    idx.clear();
    rep(i, 6000) g[i].clear();
    memset(aru, 0, sizeof(aru));
    V = 0;

    cin >> src >> dst;
    S = getidx(src);
    T = getidx(dst);
    rep(i, m) {
      string a, b;
      int d;
      cin >> a >> b >> d;
      g[getidx(a)].push_back(P(getidx(b), d));
      g[getidx(b)].push_back(P(getidx(a), d));
    }
    rep(i, n) {
      string a;
      cin >> a;
      aru[getidx(a)] = true;
    }

    priority_queue<state> que;
    que.push((state){S, C * 10, 0});
    rep(i, V) rep(j, C * 10 + 1) dist[i][j] = INF;
    while (que.size()) {
      state s = que.top();
      que.pop();
      if (dist[s.v][s.r] != INF)
        continue;
      dist[s.v][s.r] = s.d;
      for (P e : g[s.v]) {
        if (s.r < e.se)
          continue;
        que.push((state){e.fi, s.r - e.se, s.d + e.se});
      }
      if (s.r < C * 10 && aru[s.v]) {
        que.push((state){s.v, C * 10, s.d});
      }
    }

    int res = INF;
    rep(j, C * 10 + 1) minch(res, dist[T][j]);
    if (res == INF)
      cout << -1 << endl;
    else
      cout << res << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define fi first
#define se second
#define repl(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX / 3
#define mod 1000000007

struct state {
  int v, r, d;
};

bool operator<(const state &a, const state &b) { return a.d > b.d; }

int n, m, C;
string src, dst;
int S, T;
map<string, int> idx;
vector<P> g[300];
bool aru[300];
int dist[300][2010];
int V = 0;

int getidx(string s) {
  if (idx.find(s) != idx.end())
    return idx[s];
  idx[s] = V++;
  return idx[s];
}

int main() {
  while (1) {
    cin >> m >> n >> C;
    if (m == 0 && n == 0)
      break;

    idx.clear();
    rep(i, 300) g[i].clear();
    memset(aru, 0, sizeof(aru));
    V = 0;

    cin >> src >> dst;
    S = getidx(src);
    T = getidx(dst);
    rep(i, m) {
      string a, b;
      int d;
      cin >> a >> b >> d;
      g[getidx(a)].push_back(P(getidx(b), d));
      g[getidx(b)].push_back(P(getidx(a), d));
    }
    rep(i, n) {
      string a;
      cin >> a;
      aru[getidx(a)] = true;
    }

    priority_queue<state> que;
    que.push((state){S, C * 10, 0});
    rep(i, 300) rep(j, 2010) dist[i][j] = INF;
    while (que.size()) {
      state s = que.top();
      que.pop();
      if (dist[s.v][s.r] != INF)
        continue;
      dist[s.v][s.r] = s.d;
      for (P e : g[s.v]) {
        if (s.r < e.se)
          continue;
        que.push((state){e.fi, s.r - e.se, s.d + e.se});
      }
      if (s.r < C * 10 && aru[s.v]) {
        que.push((state){s.v, C * 10, s.d});
      }
    }

    int res = INF;
    rep(j, 2010) minch(res, dist[T][j]);
    if (res == INF)
      cout << -1 << endl;
    else
      cout << res << endl;
  }
  return 0;
}