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

#include <algorithm>
#include <iostream>
#include <utility>

using namespace std;

int kInf = 1 << 20;
int dtime[101][101];
int dcost[101][101];

int n, m;

void wf() {
  for (int k = 1; k <= m; k++)
    for (int i = 1; i <= m; i++)
      for (int j = 1; j <= m; j++) {
        dtime[i][j] = min(dtime[i][j], dtime[i][k] + dtime[k][j]);
        dcost[i][j] = min(dcost[i][j], dcost[i][k] + dcost[k][j]);
      }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  while (cin >> n >> m, n || m) {
    fill(dtime[0], dtime[101], kInf);
    fill(dcost[0], dcost[101], kInf);
    for (int i = 0; i < 101; i++)
      dtime[i][i] = dcost[i][i] = 0;
    for (int i = 0; i < n; i++) {
      int a, b, cost, time;
      cin >> a >> b >> cost >> time;
      dtime[a][b] = dtime[b][a] = time;
      dcost[a][b] = dcost[b][a] = cost;
    }
    wf();
    int k;
    cin >> k;
    for (int i = 0; i < k; i++) {
      int p, q, r;
      cin >> p >> q >> r;
      if (r)
        cout << dtime[p][q] << endl;
      else
        cout << dcost[p][q] << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
class NextNodesData {
public:
  int nextNodesName;
  int nextNodesMany;
  int nextNodesTime;
};
class Nodes {
public:
  vector<NextNodesData> nextNodes;
  int name;
  int minValue;
  bool fixed;
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<Nodes> nodesList;
  for (int i = 0; i < M; i++) {
    Nodes nodes;
    nodes.name = i + 1;
    nodesList.push_back(nodes);
  }
  for (int i = 0; i < N; i++) {
    int Start;
    int End;
    int Many;
    int Time;
    cin >> Start >> End >> Many >> Time;

    NextNodesData nodes;
    nodes.nextNodesName = End;
    nodes.nextNodesMany = Many;
    nodes.nextNodesTime = Time;
    nodesList[Start - 1].nextNodes.push_back(nodes);
  }

  int Query;
  cin >> Query;

  for (int i = 0; i < Query; i++) {

    //???????????????
    for (int j = 0; j < nodesList.size(); j++) {
      nodesList[j].fixed = false;
    }
    int Start;
    int End;
    int mode;

    cin >> Start >> End;
    cin >> mode;

    if (Start == End) {
      cout << 0 << endl;
      continue;
    }

    nodesList[Start - 1].fixed = true;
    nodesList[Start - 1].minValue = 0;
    int nextFixedNodesName = Start;

    vector<Nodes> candidate;
    while (1) {
      //??????????¢????????????°??????????´????????????????????????¨???????????????????????????
      for (int j = 0; j < nodesList[nextFixedNodesName - 1].nextNodes.size();
           j++) {

        Nodes obj;
        obj.name = nodesList[nextFixedNodesName - 1].nextNodes[j].nextNodesName;
        //??¢??????????????????????????????????????????????????????
        if (nodesList[obj.name - 1].fixed == true) {
          continue;
        }
        if (mode == 0) {
          obj.minValue =
              nodesList[nextFixedNodesName - 1].minValue +
              nodesList[nextFixedNodesName - 1].nextNodes[j].nextNodesMany;
        } else {
          obj.minValue =
              nodesList[nextFixedNodesName - 1].minValue +
              nodesList[nextFixedNodesName - 1].nextNodes[j].nextNodesTime;
        }
        //?¬???????????????????????????????????????????
        candidate.push_back(obj);
      }

      int minValue = 1001;
      int minName = -1;
      //?¬????????????????????£???????????°???????????????¢???
      for (int j = 0; j < candidate.size(); j++) {
        if (candidate.size() == 0) {
          cout << 0 << endl;
        }
        if (candidate[j].minValue < minValue) {
          minValue = candidate[j].minValue;
          minName = candidate[j].name;
        }
      }
      if (minName == -1) {
        cout << 0 << endl;
      }
      if (minName == End) {
        cout << minValue << endl;
        break;
      }
      nodesList[minName - 1].minValue = minValue;
      nodesList[minName - 1].fixed = true;
      nextFixedNodesName = minName;

      for (auto itr = candidate.begin(); itr != candidate.end();) {
        if (nodesList[itr->name - 1].fixed == true) {
          itr = candidate.erase(itr);
        } else {
          itr++;
        }
      }
    }
  }

  return 0;
}