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

#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
  for (int tt = 0;; tt++) {
    int n, m, cap;
    cin >> n >> m >> cap;
    if (n == 0)
      break;
    cap *= 10;
    map<string, int> map;
    string currN, destN;
    cin >> currN >> destN;
    auto mapping = [&map](const string &city) {
      if (map.find(city) == map.end())
        map.insert(make_pair(city, map.size()));
      return map[city];
    };
    int curr = mapping(currN);
    int dest = mapping(destN);
    vector<vector<pair<int, int>>> es(6002, vector<pair<int, int>>());
    for (int i = 0; i < n; i++) {
      string src, tgt;
      int d;
      cin >> src >> tgt >> d;
      int s = mapping(src);
      int t = mapping(tgt);
      es[s].push_back(make_pair(t, d));
      es[t].push_back(make_pair(s, d));
    }
    vector<bool> gs(6002, false);
    for (int i = 0; i < m; i++) {
      string city;
      cin >> city;
      gs[mapping(city)] = true;
    }
    const int BIG = 6002 * 2000 * 2 * 2;
    const int nn = map.size();

    vector<vector<int>> ds(nn, vector<int>(cap + 1, BIG));
    vector<vector<bool>> fixed(nn, vector<bool>(cap + 1, false));
    priority_queue<pair<int, pair<int, int>>> que;
    // Dijkstra
    que.push(make_pair(-0, make_pair(curr, cap)));
    while (que.size() > 0) {
      auto dvc = que.top();
      que.pop();
      const int d = -dvc.first;
      const int v = dvc.second.first;
      const int c = dvc.second.second;
      if (fixed[v][c])
        continue;
      fixed[v][c] = true;
      ds[v][c] = d;
      for (auto it = es[v].begin(); it != es[v].end(); it++) {
        int cc = c - it->second;
        if (cc >= 0) {
          int i = it->first;
          int dd = d + it->second;
          if (gs[i])
            cc = cap; // gas station
          if (ds[i][cc] > dd) {
            ds[i][cc] = dd;
            que.push(make_pair(-dd, make_pair(i, cc)));
          }
        }
      }
    }
    int min = BIG;
    for (int i = 0; i <= cap; i++) {
      if (min > ds[dest][i]) {
        min = ds[dest][i];
      }
    }
    cout << (min == BIG ? -1 : min) << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
  for (;;) {
    int n, m, cap;
    cin >> n >> m >> cap;
    if (n == 0)
      break;
    cap *= 10;
    map<string, int> map;
    string currN, destN;
    cin >> currN >> destN;
    auto mapping = [&map](const string &city) {
      if (map.find(city) == map.end())
        map.insert(make_pair(city, map.size()));
      return map[city];
    };
    int curr = mapping(currN);
    int dest = mapping(destN);
    vector<vector<pair<int, int>>> es(2000, vector<pair<int, int>>());
    for (int i = 0; i < n; i++) {
      string src, tgt;
      int d;
      cin >> src >> tgt >> d;
      int s = mapping(src);
      int t = mapping(tgt);
      es[s].push_back(make_pair(t, d));
      es[t].push_back(make_pair(s, d));
    }
    vector<bool> gs(2000, false);
    for (int i = 0; i < m; i++) {
      string city;
      cin >> city;
      gs[mapping(city)] = true;
    }
    const int BIG = 3000 * 2000 * 2 * 2;
    const int nn = map.size();
    vector<vector<int>> ds(nn, vector<int>(cap + 1, BIG));
    vector<vector<bool>> fixed(nn, vector<bool>(cap + 1, false));
    priority_queue<pair<int, pair<int, int>>> que;
    // Dijkstra
    que.push(make_pair(0, make_pair(curr, cap)));
    while (que.size() > 0) {
      auto dvc = que.top();
      que.pop();
      const int d = dvc.first;
      const int v = dvc.second.first;
      const int c = dvc.second.second;
      if (fixed[v][c])
        continue;
      fixed[v][c] = true;
      ds[v][c] = d;
      for (auto it = es[v].begin(); it != es[v].end(); it++) {
        int cc = c - it->second;
        if (cc >= 0) {
          int i = it->first;
          int dd = d + it->second;
          if (gs[i])
            cc = cap; // gas station
          if (ds[i][cc] > dd) {
            ds[i][cc] = dd;
            que.push(make_pair(dd, make_pair(i, cc)));
          }
        }
      }
    }
    int min = BIG;
    for (int i = 0; i <= cap; i++) {
      if (min > ds[dest][i]) {
        min = ds[dest][i];
      }
    }
    cout << (min == BIG ? -1 : min) << endl;
  }
  return 0;
}