alexjercan/bugnet huggingface dataset:
Problem p00212 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <queue>
#include <vector>
using namespace std;

struct state {
  int node;
  int ticket;
  int cost;
  state(int n, int t, int c) : node(n), ticket(t), cost(c) {}
  bool operator<(const state &s) const { return cost > s.cost; }
};

int main() {
  int c, n, m, s, d;
  while (cin >> c >> n >> m >> s >> d && c != 0) {
    --s;
    --d;
    vector<vector<pair<int, int>>> g(n);
    for (int i = 0; i < m; i++) {
      int a, b, f;
      cin >> a >> b >> f;
      --a;
      --b;
      g[a].push_back(make_pair(b, f));
      g[b].push_back(make_pair(a, f));
    }

    priority_queue<state> q;
    q.push(state(s, c, 0));
    vector<vector<int>> city(n, vector<int>(c + 1, 1000000));
    city[s][c] = 0;
    while (!q.empty()) {
      const state s = q.top();
      q.pop();
      if (s.node == d) {
        cout << s.cost << endl;
        break;
      }

      city[s.node][s.ticket] = s.cost;
      for (vector<pair<int, int>>::const_iterator it(g[s.node].begin());
           it != g[s.node].end(); ++it) {
        const int next = it->first;
        const int cost = s.cost + it->second;
        if (cost < city[next][s.ticket]) {
          city[next][s.ticket] = cost;
          q.push(state(next, s.ticket, cost));
        }
        if (s.ticket > 0) {
          const int cost2 = s.cost + it->second / 2;
          if (cost2 < city[next][s.ticket - 1]) {
            city[next][s.ticket - 1] = cost2;
            q.push(state(next, s.ticket - 1, cost2));
          }
        }
      }
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <queue>
#include <vector>
using namespace std;

struct state {
  int node;
  int ticket;
  int cost;
  state(int n, int t, int c) : node(n), ticket(t), cost(c) {}
  bool operator<(const state &s) const { return cost > s.cost; }
};

int main() {
  int c, n, m, s, d;
  while (cin >> c >> n >> m >> s >> d && c != 0) {
    --s;
    --d;
    vector<vector<pair<int, int>>> g(n);
    for (int i = 0; i < m; i++) {
      int a, b, f;
      cin >> a >> b >> f;
      --a;
      --b;
      g[a].push_back(make_pair(b, f));
      g[b].push_back(make_pair(a, f));
    }

    priority_queue<state> q;
    q.push(state(s, c, 0));
    vector<vector<int>> city(n, vector<int>(c, 1000000));
    city[s][c] = 0;
    while (!q.empty()) {
      const state s = q.top();
      q.pop();
      if (s.node == d) {
        cout << s.cost << endl;
        break;
      }

      city[s.node][s.ticket] = s.cost;
      for (vector<pair<int, int>>::const_iterator it(g[s.node].begin());
           it != g[s.node].end(); ++it) {
        const int next = it->first;
        const int cost = s.cost + it->second;
        if (cost < city[next][s.ticket]) {
          city[next][s.ticket] = cost;
          q.push(state(next, s.ticket, cost));
        }
        if (s.ticket > 0) {
          const int cost2 = s.cost + it->second / 2;
          if (cost2 < city[next][s.ticket - 1]) {
            city[next][s.ticket - 1] = cost2;
            q.push(state(next, s.ticket - 1, cost2));
          }
        }
      }
    }
  }
  return 0;
}
Problem p00212 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;

#define MAX 100
#define INF 1000000
int G[MAX][MAX];
int c, n, m, s, d, a, b, f;

int dijkstra() {
  int D[MAX][11];
  bool visited[MAX][11];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= c; j++) {
      D[i][j] = INF;
      visited[i][j] = false;
    }
  }
  D[s][c] = 0;
  while (true) {
    int u, w, minv = INF;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j <= c; j++) {
        if (!visited[i][j] && minv > D[i][j]) {
          minv = D[i][j];
          u = i;
          w = j;
        }
      }
    }
    if (minv == INF) {
      break;
    }
    visited[u][w] = true;
    for (int v = 0; v < n; v++) {
      if (G[u][v] == INF) {
        continue;
      }
      D[v][w] = min(D[v][w], D[u][w] + G[u][v]);
      if (w) {
        D[v][w - 1] = min(D[v][w - 1], D[u][w] + G[u][v] / 2);
      }
    }
  }
  int minv = INF;
  for (int i = 0; i <= c; i++) {
    minv = min(minv, D[d][i]);
  }
  return minv;
}

int main() {
  while (true) {
    cin >> c >> n >> m >> s >> d;
    if (s == 0 && d == 0) {
      break;
    }
    s--;
    d--;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        G[i][j] = INF;
      }
    }
    for (int i = 0; i < m; i++) {
      cin >> a >> b >> f;
      a--;
      b--;
      G[a][b] = G[b][a] = f;
    }
    cout << dijkstra() << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;

#define MAX 100
int INF = 1000000;
int G[MAX][MAX];
int c, n, m, s, d, a, b, f;

int dijkstra() {
  int D[MAX][11];
  bool visited[MAX][11];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= c; j++) {
      D[i][j] = INF;
      visited[i][j] = false;
    }
  }
  D[s][c] = 0;
  while (true) {
    int u = 0, w = 0, minv = INF;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j <= c; j++) {
        if (!visited[i][j] && minv > D[i][j]) {
          minv = D[i][j];
          u = i;
          w = j;
        }
      }
    }
    if (minv == INF) {
      break;
    }
    visited[u][w] = true;
    for (int v = 0; v < n; v++) {
      if (G[u][v] == INF) {
        continue;
      }
      D[v][w] = min(D[v][w], D[u][w] + G[u][v]);
      if (w) {
        D[v][w - 1] = min(D[v][w - 1], D[u][w] + G[u][v] / 2);
      }
    }
  }
  int minv = INF;
  for (int i = 0; i <= c; i++) {
    minv = min(minv, D[d][i]);
  }
  return minv;
}

int main() {
  while (true) {
    cin >> c >> n >> m >> s >> d;
    if (s == 0 && d == 0) {
      break;
    }
    s--;
    d--;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        G[i][j] = INF;
      }
    }
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> f;
      a--;
      b--;
      G[a][b] = G[b][a] = f;
    }
    cout << dijkstra() << endl;
  }

  return 0;
}
Problem p00212 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 28

using namespace std;
typedef pair<int, int> P;

struct edge {
  int to;
  int cost;

  edge(int to, int cost) : to(to), cost(cost) {}
};

int d[101][11];
vector<edge> G[101];

void dijkstra(int s, int n, int ticket) {
  priority_queue<P, vector<P>, greater<P>> que;
  rep(i, n) d[i][ticket] = INF;
  d[s][ticket] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();

    int v = p.second;
    if (d[v][ticket] < p.first)
      continue;

    rep(i, G[v].size()) {
      edge e = G[v][i];
      int temp;

      if (ticket == 0) {
        temp = d[v][ticket] + e.cost;
      } else {
        temp = min(d[v][ticket] + e.cost, d[v][ticket - 1] + e.cost / 2);
      }

      if (d[e.to][ticket] > temp) {
        d[e.to][ticket] = temp;
        que.push(P(d[e.to][ticket], e.to));
      }
    }
  }
}

int main() {
  int c, n, m, s, t;
  while (cin >> c >> n >> m >> s >> t) {
    if (c == 0 && n == 0 && m == 0 && s == 0 && t == 0)
      break;

    s--;
    t--;
    rep(i, 100) G[i].clear();

    rep(i, m) {
      int a, b, cost;
      cin >> a >> b >> cost;
      a--;
      b--;

      edge e(b, cost);
      G[a].push_back(e);

      edge e2(a, cost);
      G[b].push_back(e2);
    }

    rep(i, c + 1) dijkstra(s, n, i);

    cout << d[t][c] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 28

using namespace std;
typedef pair<int, int> P;

struct edge {
  int to;
  int cost;

  edge(int to, int cost) : to(to), cost(cost) {}
};

int d[101][11];
vector<edge> G[101];

void dijkstra(int s, int n, int ticket) {
  priority_queue<P, vector<P>, greater<P>> que;
  rep(i, n) d[i][ticket] = INF;
  d[s][ticket] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();

    int v = p.second;
    if (d[v][ticket] < p.first)
      continue;

    rep(i, G[v].size()) {
      edge e = G[v][i];
      int temp;

      if (ticket == 0) {
        temp = d[v][ticket] + e.cost;
      } else {
        temp = min(d[v][ticket] + e.cost, d[v][ticket - 1] + e.cost / 2);
      }

      if (d[e.to][ticket] > temp) {
        d[e.to][ticket] = temp;
        que.push(P(d[e.to][ticket], e.to));
      }
    }
  }
}

int main() {
  int c, n, m, s, t;
  while (cin >> c >> n >> m >> s >> t) {
    if (c == 0 && n == 0 && m == 0 && s == 0 && t == 0)
      break;

    s--;
    t--;
    rep(i, 100) G[i].clear();

    rep(i, m) {
      int a, b, cost;
      cin >> a >> b >> cost;
      a--;
      b--;

      edge e(b, cost);
      G[a].push_back(e);

      edge e2(a, cost);
      G[b].push_back(e2);
    }

    rep(i, n) dijkstra(s, n, i);

    cout << d[t][c] << endl;
  }

  return 0;
}
Problem p00212 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

struct node {
  int cost;
  int c;
  int now;
  node(int C, int cc, int n) : cost(C), c(cc), now(n) {}
  bool operator>(const node &e) const { return cost > e.cost; }
};

int main() {
  int c, n, m, s, d;

  for (; cin >> c >> n >> m >> s >> d, c;) {
    int edge[n][n];
    bool close[c + 1][n];
    memset(edge, -1, sizeof(edge));
    memset(close, false, sizeof(close));
    for (int i = 0; i < m; i++) {
      int a, b, f;
      cin >> a >> b >> f;
      a--;
      b--;
      edge[a][b] = f;
      edge[b][a] = f;
    }
    s--;
    d--;
    priority_queue<node, vector<node>, greater<node>> qu;
    qu.push(node(0, c, s));
    while (!qu.empty()) {
      node tmp = qu.top();
      //	  cout<<tmp.now<<" "<<tmp.cost<<" "<<tmp.c<<endl;
      qu.pop();
      if (close[tmp.c][tmp.now])
        continue;
      close[tmp.c][tmp.now] = true;
      if (tmp.now == d) {
        cout << tmp.cost << endl;
        break;
      }
      for (int i = 0; i < n; i++) {
        if (edge[tmp.now][i] != -1) {
          if (!close[tmp.c][i])
            qu.push(node(edge[tmp.now][i] + tmp.cost, tmp.c, i));
          if (tmp.c > 0 && !close[tmp.c - 1][i])
            qu.push(node(edge[tmp.now][i] / 2 + tmp.cost, tmp.c - 1, i));
        }
      }
    }
  }
}

Error: MLE

Fixed submission:

#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

struct node {
  int cost;
  int c;
  int now;
  node(int C, int cc, int n) : cost(C), c(cc), now(n) {}
  bool operator>(const node &e) const { return cost > e.cost; }
};

int main() {
  int c, n, m, s, d;

  for (; cin >> c >> n >> m >> s >> d, c;) {
    int edge[n][n];
    bool close[c + 1][n];
    memset(edge, -1, sizeof(edge));
    memset(close, false, sizeof(close));
    for (int i = 0; i < m; i++) {
      int a, b, f;
      cin >> a >> b >> f;
      a--;
      b--;
      edge[a][b] = f;
      edge[b][a] = f;
    }
    s--;
    d--;
    priority_queue<node, vector<node>, greater<node>> qu;
    qu.push(node(0, c, s));
    while (!qu.empty()) {
      node tmp = qu.top();
      //	  cout<<tmp.now<<" "<<tmp.cost<<" "<<tmp.c<<endl;
      qu.pop();
      close[tmp.c][tmp.now] = true;
      if (tmp.now == d) {
        cout << tmp.cost << endl;
        break;
      }
      for (int i = 0; i < n; i++) {
        if (edge[tmp.now][i] != -1) {
          if (!close[tmp.c][i])
            qu.push(node(edge[tmp.now][i] + tmp.cost, tmp.c, i));
          if (tmp.c > 0 && !close[tmp.c - 1][i])
            qu.push(node(edge[tmp.now][i] / 2 + tmp.cost, tmp.c - 1, i));
        }
      }
    }
  }
}
Problem p00212 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <queue>
#include <vector>

using namespace std;

struct NODE {
  int now, cost, ticket;
  NODE(int now, int cost, int ticket) : now(now), cost(cost), ticket(ticket) {}
  NODE() {}
};

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

int main(void) {
  int c, n, m, s, d;
  while (cin >> c >> n >> m >> s >> d, n) {
    vector<NODE> edge[150];
    int a, b, f;
    for (int i = 0; i < m; i++) {
      cin >> a >> b >> f;
      edge[a].push_back(NODE(b, f, -1));
      edge[b].push_back(NODE(a, f, -1));
    }

    bool visited[150][20] = {};
    priority_queue<NODE> Q;
    Q.push(NODE(s, 0, c));
    while (Q.size()) {
      NODE q = Q.top();
      Q.pop();
      if (visited[q.now][q.ticket])
        continue;
      visited[q.now][q.ticket] = true;
      if (q.now == d) {
        cout << q.cost << endl;
        break;
      }
      for (int i = 0; i < edge[q.now].size(); i++) {
        Q.push(
            NODE(edge[q.now][i].now, q.cost + edge[q.now][i].cost, q.ticket));
        if (q.ticket) {
          Q.push(NODE(edge[q.now][i].now, q.cost + (edge[q.now][i].cost / 2),
                      q.ticket - 1));
        }
      }
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <queue>
#include <vector>

using namespace std;

struct NODE {
  int now, cost, ticket;
  NODE(int now, int cost, int ticket) : now(now), cost(cost), ticket(ticket) {}
  NODE() {}
};

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

int main(void) {
  int c, n, m, s, d;
  while (cin >> c >> n >> m >> s >> d, n) {
    vector<NODE> edge[150];
    int a, b, f;
    for (int i = 0; i < m; i++) {
      cin >> a >> b >> f;
      edge[a].push_back(NODE(b, f, -1));
      edge[b].push_back(NODE(a, f, -1));
    }

    priority_queue<NODE> Q;
    Q.push(NODE(s, 0, c));
    while (Q.size()) {
      NODE q = Q.top();
      Q.pop();
      if (q.now == d) {
        cout << q.cost << endl;
        break;
      }
      for (int i = 0; i < edge[q.now].size(); i++) {
        Q.push(
            NODE(edge[q.now][i].now, q.cost + edge[q.now][i].cost, q.ticket));
        if (q.ticket) {
          Q.push(NODE(edge[q.now][i].now, q.cost + (edge[q.now][i].cost / 2),
                      q.ticket - 1));
        }
      }
    }
  }

  return 0;
}
Problem p00212 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

int calcCost(int c, int n, vector<int> path, vector<int> rt) {
  priority_queue<int> costs;
  for (int i = 1; i < rt.size(); i++) {
    costs.push(path[rt[i] + n * rt[i - 1]]);
  }
  int total = 0;
  while (costs.size() && c--) {
    total += costs.top() / 2;
    costs.pop();
  }
  while (costs.size()) {
    total += costs.top();
    costs.pop();
  }
  return total;
}
int main() {
  for (;;) {
    int c, n, m, s, d;
    cin >> c >> n >> m >> s >> d;
    if (c + n + m + s + d == 0)
      break;
    vector<pair<int, vector<int>>> route(n, make_pair(-1, vector<int>()));
    vector<int> path(n * n, -1);
    for (int i = 0; i < m; i++) {
      int a, b, f;
      cin >> a >> b >> f;
      path[--a + n * --b] = path[b + n * a] = f;
    }
    priority_queue<pair<int, vector<int>>, vector<pair<int, vector<int>>>,
                   greater<pair<int, vector<int>>>>
        pq;
    pq.push(make_pair(0, vector<int>(1, s - 1)));
    while (pq.size()) {
      int cur = *(pq.top().second.rbegin());
      if (route[cur].first == -1) {
        route[cur] = pq.top();
        for (int i = 0; i < n; i++) {
          if (route[i].first == -1 && path[i + n * cur] != -1) {
            auto copy = pq.top();
            copy.second.push_back(i);
            copy.first = calcCost(c, n, path, copy.second);
            pq.push(copy);
          }
        }
      }
      pq.pop();
    }
    cout << route[d - 1].first << endl;
  }
}

Error: WA

Fixed submission:

#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

int calcCost(int c, int n, vector<int> path, vector<int> rt) {
  priority_queue<int> costs;
  for (int i = 1; i < rt.size(); i++) {
    costs.push(path[rt[i] + n * rt[i - 1]]);
  }
  int total = 0;
  while (costs.size() && c--) {
    total += costs.top() / 2;
    costs.pop();
  }
  while (costs.size()) {
    total += costs.top();
    costs.pop();
  }
  return total;
}
int main() {
  for (;;) {
    int c, n, m, s, d;
    cin >> c >> n >> m >> s >> d;
    if (c + n + m + s + d == 0)
      break;
    vector<pair<int, vector<int>>> route(n + 32, make_pair(-1, vector<int>()));
    vector<int> path(n * n + 21, -1);
    for (int i = 0; i < m; i++) {
      int a, b, f;
      cin >> a >> b >> f;
      path[--a + n * --b] = path[b + n * a] = f;
    }
    priority_queue<pair<int, vector<int>>, vector<pair<int, vector<int>>>,
                   greater<pair<int, vector<int>>>>
        pq;
    pq.push(make_pair(0, vector<int>(1, s - 1)));
    while (pq.size()) {
      int cur = *(pq.top().second.rbegin());
      if (route[cur].first == -1) {
        route[cur] = pq.top();
        for (int i = 0; i < m; i++) {
          if (route[i].first == -1 && path[i + n * cur] != -1) {
            auto copy = pq.top();
            copy.second.push_back(i);
            copy.first = calcCost(c, n, path, copy.second);
            pq.push(copy);
          }
        }
      }
      pq.pop();
    }
    cout << route[d - 1].first << endl;
  }
}
Problem p00212 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
#define MAX 101
#define INF 9999999

int c, n, m, s, d, a, b, f, cost[MAX + 1][MAX + 1], dd[MAX + 1][MAX + 1];
bool used[MAX + 1][MAX + 1];
int x, y;

int dijkstra(int s, int d, int c) {
  fill(dd[0], dd[MAX], INF);
  fill(used[0], used[MAX], false);

  dd[c][s - 1] = 0;
  while (true) {
    int Mini = -1, Minj;

    for (int i = y; i <= x; i++) {
      for (int j = 0; j <= c; j++) {
        if ((dd[j][i] < dd[Minj][Mini] || Mini == -1) && !used[j][i]) {
          Mini = i;
          Minj = j;
        }
      }
    }

    if (Mini == -1)
      break;
    used[Minj][Mini] = true;

    for (int i = y; i <= x; i++) {
      dd[Minj][i] = min(dd[Minj][i], dd[Minj][Mini] + cost[Mini][i]);
      if (Minj > 0)
        dd[Minj - 1][i] =
            min(dd[Minj - 1][i], dd[Minj][Mini] + cost[Mini][i] / 2);
    }
  }

  int res = INF;
  for (int i = 0; i <= c; i++) {
    res = min(res, dd[i][d - 1]);
  }

  return res;
}

int main() {
  x = 0;
  y = INF;
  while (cin >> c >> n >> m >> s >> d, c + n + m + s + d) {
    fill(cost[0], cost[MAX], INF);
    for (int i = 0; i < m; i++) {
      cin >> a >> b >> f;
      cost[a - 1][b - 1] = f;
      cost[b - 1][a - 1] = f;
      x = max(x, max(a - 1, b - 1));
      y = min(y, min(a - 1, b - 1));
    }

    cout << dijkstra(s, d, c) << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
#define MAX 101
#define INF 9999999

int c, n, m, s, d, a, b, f, cost[MAX + 1][MAX + 1], dd[MAX + 1][MAX + 1];
bool used[MAX + 1][MAX + 1];

int dijkstra(int s, int d, int c) {
  fill(dd[0], dd[MAX], INF);
  fill(used[0], used[MAX], false);

  dd[c][s - 1] = 0;
  while (true) {
    int Mini = -1, Minj;

    for (int i = 0; i < n; i++) {
      for (int j = 0; j <= c; j++) {
        if ((dd[j][i] < dd[Minj][Mini] || Mini == -1) && !used[j][i]) {
          Mini = i;
          Minj = j;
        }
      }
    }

    if (Mini == -1)
      break;
    used[Minj][Mini] = true;

    for (int i = 0; i < n; i++) {
      dd[Minj][i] = min(dd[Minj][i], dd[Minj][Mini] + cost[Mini][i]);
      if (Minj > 0)
        dd[Minj - 1][i] =
            min(dd[Minj - 1][i], dd[Minj][Mini] + cost[Mini][i] / 2);
    }
  }

  int res = INF;
  for (int i = 0; i <= c; i++) {
    res = min(res, dd[i][d - 1]);
  }

  return res;
}

int main() {
  while (cin >> c >> n >> m >> s >> d, c + n + m + s + d) {
    fill(cost[0], cost[MAX], INF);
    for (int i = 0; i < m; i++) {
      cin >> a >> b >> f;
      cost[a - 1][b - 1] = f;
      cost[b - 1][a - 1] = f;
    }

    cout << dijkstra(s, d, c) << endl;
  }

  return 0;
}
Problem p00212 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#define INF 10e8
using namespace std;

int c, n, m, s, d;

int cost[101][101];
int state[101][11];
struct node {
  int c; // cost
  int n; // number
  int t; // times
  bool operator>(node b) const { return c > b.c; }
};

int dijkstra(int s, int g) {
  node start;
  start.c = 0, start.n = s, start.t = c;
  priority_queue<node, vector<node>, greater<node>> q;
  q.push(start);
  while (!q.empty()) {
    node cur = q.top();
    q.pop();
    if (cur.n == g) {
      int ans = cur.c;
      return ans;
    }
    if (state[cur.n][cur.t] <= cur.c)
      continue;
    else
      state[cur.n][cur.t] = cur.c;
    for (int i = 1; i <= n; i++) {
      if (cur.n == i)
        continue;
      node next;
      if (cur.t > 0) {
        next.c = cur.c + (cost[cur.n][i] / 2);
        next.n = i;
        next.t = cur.t - 1;
        q.push(next);
      }
      next.c = cur.c + cost[cur.n][i];
      next.n = i;
      next.t = cur.t;
      q.push(next);
    }
  }
}
int main(void) {
  while (cin >> c >> n >> m >> s >> d, c | n | m | s | d) {
    for (int i = 1; i <= n; i++)
      for (int j = 0; j <= c; j++)
        state[i][j] = INF;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        cost[i][j] = INF;
    int a, b, f;
    for (int i = 0; i < m; i++) {
      cin >> a >> b >> f;
      cost[a][b] = cost[b][a] = f;
    }
    int ans = dijkstra(s, d);
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#define INF 10e6
using namespace std;

int c, n, m, s, d;

int cost[101][101];

struct node {
  int c; // cost
  int n; // number
  int t; // times
  bool operator>(node b) const { return c > b.c; }
};

int dijkstra(int s, int g) {
  node start;
  start.c = 0, start.n = s, start.t = c;
  priority_queue<node, vector<node>, greater<node>> q;
  q.push(start);
  while (!q.empty()) {
    node cur = q.top();
    q.pop();
    if (cur.n == g) {
      int ans = cur.c;
      return ans;
    }
    for (int i = 1; i <= n; i++) {
      if (cur.n == i)
        continue;
      node next;
      if (cur.t > 0) {
        next.c = cur.c + (cost[cur.n][i] / 2);
        next.n = i;
        next.t = cur.t - 1;
        q.push(next);
      }
      next.c = cur.c + cost[cur.n][i];
      next.n = i;
      next.t = cur.t;
      q.push(next);
    }
  }
  return INF;
}
int main(void) {
  while (cin >> c >> n >> m >> s >> d, c | n | m | s | d) {
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        cost[i][j] = INF;
    int a, b, f;
    for (int i = 0; i < m; i++) {
      cin >> a >> b >> f;
      cost[a][b] = cost[b][a] = f;
    }
    int ans = dijkstra(s, d);
    cout << ans << endl;
  }
  return 0;
}