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

#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define MAX 100000
#define MAX_NODE_ID 101
#define MAX_TICKET 11
class Node {
public:
  int id;
  int cost;
  int ticket;
  Node(int i, int c, int t) {
    id = i;
    cost = c;
    ticket = t;
  }
  bool operator<(const Node &o) const { return cost > o.cost; }
};
typedef priority_queue<Node> PQ;
int table[MAX_NODE_ID][MAX_NODE_ID];
bool visited[MAX_NODE_ID][MAX_TICKET];
int main() {

  for (int c, n, m, s, d;
       cin >> c >> n >> m >> s >> d && (c || n || m || s || d);) {
    for (int i = 0; i < MAX_NODE_ID; i++)
      for (int j = 0; j < MAX_NODE_ID; j++)
        table[i][j] = MAX;
    for (int i = 0; i < MAX_NODE_ID; i++)
      for (int j = 0; j < MAX_TICKET; j++)
        visited[i][j] = false;
    for (int i = 0, a, b, f; i < m && cin >> a >> b >> f; i++) {
      table[a][b] = f;
      table[b][a] = f;
      //			cout<<"table["<<a<<"]["<<b<<"]"<<table[a][b]<<endl;
      //			cout<<"table["<<b<<"]["<<a<<"]"<<table[b][a]<<endl;
    }
    PQ pq;
    Node start(s, 0, c);
    pq.push(start);
    while (!pq.empty()) {
      int current_node = pq.top().id;
      int current_cost = pq.top().cost;
      int current_ticket = pq.top().ticket;
      //			cout<<"current:"<<current_node<<endl;
      if (current_node == d)
        break;
      if (visited[current_node][current_ticket])
        ;
      else {
        for (int i = 1; i <= n; i++) {
          if (current_node == i)
            continue;
          if (table[current_node][i] == MAX)
            continue;
          //				cout<<"["<<current_node<<"]["<<i<<"]"<<"cost:"<<table[current_node][i]<<endl;
          Node node1(i, current_cost + table[current_node][i], current_ticket);
          pq.push(node1);
          visited[current_node][current_ticket] = true;
          if (current_ticket > 0) {
            Node node2(i, current_cost + (table[current_node][i] / 2),
                       current_ticket - 1);
            pq.push(node2);
            visited[current_node][current_ticket - 1] = true;
          }
        }
      }
      pq.pop();
    }
    cout << pq.top().cost << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define MAX 100000
#define MAX_NODE_ID 101
#define MAX_TICKET 11
class Node {
public:
  int id;
  int cost;
  int ticket;
  Node(int i, int c, int t) {
    id = i;
    cost = c;
    ticket = t;
  }
  bool operator<(const Node &o) const { return cost > o.cost; }
};
typedef priority_queue<Node> PQ;
int table[MAX_NODE_ID][MAX_NODE_ID];
bool visited[MAX_NODE_ID][MAX_TICKET];
int main() {

  for (int c, n, m, s, d;
       cin >> c >> n >> m >> s >> d && (c || n || m || s || d);) {
    for (int i = 1; i < MAX_NODE_ID; i++)
      for (int j = 1; j < MAX_NODE_ID; j++)
        table[i][j] = MAX;
    for (int i = 1, a, b, f; i < m && cin >> a >> b >> f; i++) {
      table[a][b] = f;
      table[b][a] = f;
      //			cout<<"table["<<a<<"]["<<b<<"]"<<table[a][b]<<endl;
      //			cout<<"table["<<b<<"]["<<a<<"]"<<table[b][a]<<endl;
    }
    PQ pq;

    pq.push(Node(s, 0, c));
    while (!pq.empty()) {
      int current_node = pq.top().id;
      int current_cost = pq.top().cost;
      int current_ticket = pq.top().ticket;
      //			cout<<"current:"<<current_node<<endl;
      if (current_node == d)
        break;
      if (visited[current_node][current_ticket])
        ;
      else {
        for (int i = 1; i <= n; i++) {
          if (current_node == i)
            continue;
          if (table[current_node][i] == MAX)
            continue;
          //				cout<<"["<<current_node<<"]["<<i<<"]"<<"cost:"<<table[current_node][i]<<endl;

          pq.push(
              Node(i, current_cost + table[current_node][i], current_ticket));
          if (current_ticket > 0) {
            pq.push(Node(i, current_cost + (table[current_node][i] / 2),
                         current_ticket - 1));
          }
          visited[current_node][i] = true;
        }
      }
      pq.pop();
    }
    cout << pq.top().cost << endl;
  }
  return 0;
}