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

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

struct Edge {
  int to, cost, time;
};

typedef pair<int, int> P;

const int MAX_V = 3010;
const int INF = 1 << 30;

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

  int n, m;
  while (cin >> n >> m && n != 0 && m != 0) {

    vector<Edge> vec[MAX_V];
    int d[MAX_V];

    for (int i = 0; i < n; ++i) {
      int a, b, c, t;
      cin >> a >> b >> c >> t;
      --a, --b;
      vec[a].push_back(Edge{b, c, t});
      vec[b].push_back(Edge{a, c, t});
    }

    int k;
    cin >> k;

    while (k > 0) {
      --k;
      priority_queue<P, vector<P>, greater<P>> que;
      fill(d, d + n, INF);

      int p, q, r;
      cin >> p >> q >> r;
      --p, --q;

      d[p] = 0;
      que.push(P(0, p));

      while (!que.empty()) {
        P p0 = que.top();
        que.pop();
        int v = p0.second;
        if (d[v] < p0.first)
          continue;
        for (int i = 0; i < vec[v].size(); ++i) {
          Edge e = vec[v][i];
          if (r == 0 && d[e.to] > d[v] + e.cost) {
            d[e.to] = d[v] + e.cost;
            que.push(P(d[e.to], e.to));
          }
          if (r == 1 && d[e.to] > d[v] + e.time) {
            d[e.to] = d[v] + e.time;
            que.push(P(d[e.to], e.to));
          }
        }
      }

      cout << d[q] << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

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

struct Edge {
  int to, cost, time;
};

typedef pair<int, int> P;

const int MAX_V = 110;
const int INF = 1 << 30;

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

  int n, m;
  while (cin >> n >> m && n != 0 && m != 0) {

    vector<Edge> vec[MAX_V];
    int d[MAX_V];

    for (int i = 0; i < n; ++i) {
      int a, b, c, t;
      cin >> a >> b >> c >> t;
      --a, --b;
      vec[a].push_back(Edge{b, c, t});
      vec[b].push_back(Edge{a, c, t});
    }

    int k;
    cin >> k;

    while (k > 0) {
      --k;
      priority_queue<P, vector<P>, greater<P>> que;
      fill(d, d + n, INF);

      int p, q, r;
      cin >> p >> q >> r;
      --p, --q;

      d[p] = 0;
      que.push(P(0, p));

      while (!que.empty()) {
        P p0 = que.top();
        que.pop();
        int v = p0.second;
        if (d[v] < p0.first)
          continue;
        for (int i = 0; i < vec[v].size(); ++i) {
          Edge e = vec[v][i];
          if (r == 0 && d[e.to] > d[v] + e.cost) {
            d[e.to] = d[v] + e.cost;
            que.push(P(d[e.to], e.to));
          }
          if (r == 1 && d[e.to] > d[v] + e.time) {
            d[e.to] = d[v] + e.time;
            que.push(P(d[e.to], e.to));
          }
        }
      }

      cout << d[q] << endl;
    }
  }

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

#include <cstring>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
#define INF 100000000
int mini(int a, int b) {
  if (a < b) {
    return a;
  } else {
    return b;
  }
}

int cost(int p, int q, int m, int co[][101]) {
  int i, s[101], a, j, d[101], b;
  for (i = 0; i <= m; i++) {
    s[i] = 0;
    d[i] = INF;
  }
  a = p;
  s[a] = 1;
  d[a] = 0;
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= m; j++) {
      d[j] = mini(d[j], d[a] + co[a][j]);
    }
    s[a] = 1;
    b = INF;
    for (j = 1; j <= m; j++) {
      if (s[j] == 0 && d[j] <= b) {
        a = j;
        b = d[j];
      }
    }
    s[a] = 1;
  }
  return d[q];
}

int main() {
  while (1) {
    int i, a = 0, b = 0, p, q, r, j, k, n, m, co[101][101], ti[101][101],
           s[101], ans[200];
    for (i = 0; i < 101; i++) {
      s[i] = 0;
      for (j = 0; j < 101; j++) {
        if (i == j) {
          co[i][j] = 0;
          ti[i][j] = 0;
        } else {
          co[i][j] = INF;
          ti[i][j] = INF;
        }
      }
    }
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (i = 0; i < n; i++) {
      cin >> a >> b;
      cin >> co[a][b] >> ti[a][b];
      co[b][a] = co[a][b];
      ti[b][a] = ti[a][b];
    }
    cin >> k;
    for (i = 0; i < k; i++) {
      cin >> p >> q >> r;
      if (r == 0) {
        ans[i] = cost(p, q, m, co);
      } else {
        ans[i] = cost(p, q, m, ti);
      }
    }
    for (i = 0; i < k; i++) {
      cout << ans[i] << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
int mini(int a, int b) {
  if (a < b) {
    return a;
  } else {
    return b;
  }
}

int cost(int p, int q, int n, int co[][100]) {
  int i, s[100], a, j, min, d[100], b;
  for (i = 1; i <= n; i++) {
    s[i] = 0;
    d[i] = 2000;
  }
  a = p;
  s[a] = 1;
  min = 1500;
  d[a] = 0;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      d[j] = mini(d[j], d[a] + co[a][j]);
    }
    s[a] = 1;
    b = 2000;
    for (j = 1; j <= n; j++) {
      if (s[j] == 0 && d[j] < b) {
        a = j;
        b = d[j];
      }
    }
    s[a] = 1;
  }
  return d[q];
}

int main() {
  while (1) {
    int i, a = 0, b = 0, p, q, r, j, k, n, m, co[100][100], ti[100][100],
           s[100];
    for (i = 0; i < 100; i++) {
      s[i] = 0;
      for (j = 0; j < 100; j++) {
        if (i == j) {
          co[i][j] = 0;
          ti[i][j] = 0;
        } else {
          co[i][j] = 2000;
          ti[i][j] = 2000;
        }
      }
    }
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (i = 0; i < n; i++) {
      cin >> a >> b;
      cin >> co[a][b] >> ti[a][b];
      co[b][a] = co[a][b];
      ti[b][a] = ti[a][b];
    }
    cin >> k;
    for (i = 0; i < k; i++) {
      cin >> p >> q >> r;
      if (r == 0) {
        cout << cost(p, q, m, co) << endl;
      } else {
        cout << cost(p, q, m, ti) << endl;
      }
    }
  }
  return 0;
}
Problem p00200 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    int cost[100][100];
    int time[100][100];
    rep(i, 100) rep(j, 100) cost[i][j] = time[i][j] = 1e9;
    rep(i, 100) cost[i][i] = time[i][i] = 0;
    rep(i, n) {
      int a, b, c, t;
      cin >> a >> b >> c >> t;
      --a;
      --b;
      cost[a][b] = min(cost[a][b], c);
      time[a][b] = min(time[a][b], t);
      cost[b][a] = min(cost[b][a], c);
      time[b][a] = min(time[b][a], t);
    }
    rep(k, m) rep(i, m) rep(j, m) {
      cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
      time[i][j] = min(time[i][j], time[i][k] + time[k][j]);
    }
    int k;
    cin >> k;
    rep(i, k) {
      int p, q, r;
      cin >> p >> q >> r;
      --p;
      --q;
      if (r == 0)
        cout << cost[p][q] << endl;
      else
        cout << time[p][q] << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

struct Edge {
  int to, cost[2];
};

int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    int a, b, c, t;
    vector<Edge> edge[m];
    rep(i, n) {
      cin >> a >> b >> c >> t;
      --a;
      --b;
      Edge e;
      e.to = b;
      e.cost[0] = c;
      e.cost[1] = t;
      edge[a].push_back(e);
      e.to = a;
      edge[b].push_back(e);
    }
    int k;
    cin >> k;
    rep(iii, k) {
      int p, q, r;
      cin >> p >> q >> r;
      --p;
      --q;
      vector<int> dis;
      rep(i, m) dis.push_back(1e9);
      priority_queue<pair<int, int>, vector<pair<int, int>>,
                     greater<pair<int, int>>>
          que;
      que.push(make_pair(0, p));
      while (!que.empty()) {
        pair<int, int> now = que.top();
        que.pop();
        if (dis[now.second] <= now.first)
          continue;
        dis[now.second] = now.first;
        rep(i, edge[now.second].size()) {
          que.push(make_pair(edge[now.second][i].cost[r] + now.first,
                             edge[now.second][i].to));
        }
      }
      cout << dis[q] << endl;
    }
  }
  return 0;
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <vector>

using namespace std;

const int INF = 99999999;

class Edge {
public:
  int from, to, cost, time;
  void swap() {
    int self = from;
    from = to;
    to = self;
  }
  int getvalue(int r) {
    if (r == 0) {
      return cost;
    } else {
      return time;
    }
  }
};

vector<Edge> edge;
int n, m;

int solve(const int p, const int q, const int r);

int main() {
  edge.clear();
  while (1) {
    edge.clear();
    scanf("%d %d", &n, &m);
    if (n == 0 && m == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      Edge ed;
      scanf("%d %d %d %d", &ed.from, &ed.to, &ed.cost, &ed.time);
      edge.push_back(ed);
      ed.swap();
      edge.push_back(ed);
    }

    int k;
    scanf("%d", &k);
    for (int i = 0; i < k; i++) {
      int p, q, r;
      scanf("%d %d", &p, &q);
      if (p == 0 && q == 0) {
        return 0;
      }
      scanf("%d", &r);
      printf("%d\\n", solve(p, q, r));
    }
  }
  return 0;
}

int solve(const int p, const int q, const int r) {
  int *a = new int[m + 1];
  for (int i = 0; i <= m; i++) {
    a[i] = INF;
  }
  a[p] = 0;
  bool update;
  while (true) {
    update = false;
    vector<Edge>::iterator it = edge.begin();
    while (it != edge.end()) {
      if (a[(*it).from] != INF &&
          a[(*it).to] > a[(*it).from] + (*it).getvalue(r)) {
        a[(*it).to] = a[(*it).from] + (*it).getvalue(r);
        update = true;
      }
      it++;
    }
    if (!update) {
      break;
    }
  }

  int ans = a[q];
  return a[q];
}

Error: 0

Fixed submission:

#include <cstdio>
#include <vector>

using namespace std;

class Edge {
public:
  int from, to, cost, time;
  void Swap() {
    int self = from;
    from = to;
    to = from;
  }
  int GetValue(int r) {
    if (r == 0) {
      return cost;
    } else {
      return time;
    }
  }
};

vector<Edge> edge;
int n, m;

const int INF = 100000000;

int solve(const int p, const int q, const int r);

int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    Edge ed;
    scanf("%d %d %d %d", &ed.from, &ed.to, &ed.cost, &ed.time);
    edge.push_back(ed);
    ed.Swap();
    edge.push_back(ed);
  }
  int k;
  int p, q, r;
  scanf("%d", &k);
  while (scanf("%d %d", &p, &q) && p && q) {
    scanf("%d", &r);
    printf("%d\\n", solve(p, q, r));
  }
  return 0;
}

int solve(const int p, const int q, const int r) {
  vector<int> d(m + 1);
  for (int i = 0; i <= m; i++) {
    d[i] = INF;
  }
  d[p] = 0;

  bool flag;
  while (1) {
    flag = false;
    vector<Edge>::iterator it;
    for (it = edge.begin(); it != edge.end(); it++) {
      if (d[(*it).from] != INF &&
          d[(*it).to] > d[(*it).from] + (*it).GetValue(r)) {
        d[(*it).to] = d[(*it).from] + (*it).GetValue(r);
        flag = true;
      }
    }
    if (!flag) {
      break;
    }
  }

  return d[q];
}
Problem p00200 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <climits>
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define min(a, b) (a > b ? b : a)

int main() {
  int m, n;
  while (std::cin >> m >> n && m != 0 && n != 0) {
    int tb[n][n][2];

    rep(i, n) rep(j, n) tb[i][j][0] = tb[i][j][1] = tb[j][i][0] = tb[j][i][1] =
        (i == j ? 0 : INT_MAX / 3);
    rep(i, m) {
      int f, t, c, tm;
      std::cin >> f >> t >> c >> tm;
      f--;
      t--;
      tb[f][t][0] = tb[t][f][0] = c;
      tb[f][t][1] = tb[t][f][1] = tm;
    }
    rep(x, n) rep(y, n) rep(z, n) rep(i, 2) tb[z][y][i] = tb[y][z][i] =
        min(tb[y][z][i], tb[y][x][i] + tb[x][z][i]);

    int k;
    std::cin >> k;
    rep(i, k) {
      int s, e, q;
      std::cin >> s >> e >> q;
      s--;
      e--;
      std::cout << tb[s][e][q] << std::endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <climits>
#include <iostream>
#include <vector>

struct Edge {
  Edge(int f, int t, int c, int tm) {
    from = f;
    to = t;
    cost[0] = c;
    cost[1] = tm;
  }
  int from, to, cost[2];
};

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

  std::vector<Edge> edges;
  int n, m, k;
  while (std::cin >> n >> m && n != 0 && m != 0) {
    for (int i = 0; i < n; i++) {
      int from, to, cost, time;
      std::cin >> from >> to >> cost >> time;
      edges.push_back(Edge(from - 1, to - 1, cost, time));
    }

    std::cin >> k;
    for (int i = 0; i < k; i++) {
      auto sts = new int[m]();
      auto used = new bool[m]();
      for (int j = 0; j < m; j++) {
        sts[j] = INT_MAX;
        used[j] = false;
      }

      int start, end, query;
      std::cin >> start >> end >> query;

      int cur = start - 1;
      sts[cur] = 0;
      used[cur] = true;
      while (!used[end - 1]) {
        for (auto e : edges) {
          if (e.to == cur && sts[e.from] > sts[cur] + e.cost[query])
            sts[e.from] = sts[cur] + e.cost[query];
          if (e.from == cur && sts[e.to] > sts[cur] + e.cost[query])
            sts[e.to] = sts[cur] + e.cost[query];
        }
        for (int j = 0; j < m; j++)
          std::cout << sts[j] << ' ';
        std::cout << std::endl;

        int min_i, min_c = INT_MAX;
        for (int j = 0; j < m; j++)
          if (!used[j] && min_c > sts[j]) {
            min_i = j;
            min_c = sts[j];
          }
        used[min_i] = true;
        cur = min_i;
      }
      std::cout << sts[end - 1] << std::endl;
      delete[] sts;
      delete[] used;
    }
    edges.clear();
  }
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
#define INFTY (1 << 21)
#define MAX 100
void floyd(int m, int C[MAX][MAX], int T[MAX][MAX]) {
  for (int k = 0; k < m; k++)
    for (int i = 0; i < m; i++)
      for (int j = 0; j < m; j++) {
        C[i][j] = min(C[i][j], C[i][k] + C[k][j]);
        T[i][j] = min(T[i][j], T[i][k] + T[k][j]);
      }
}
main() {
  int n, m, a, b, c, t, k, q, C[MAX][MAX], T[MAX][MAX];
  while (cin >> n >> m && !(n == 0 && m == 0)) {
    for (int i = 0; i < m; i++)
      for (int j = 0; j < m; j++) {
        C[i][j] = T[i][j] = INFTY;
      }
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> c >> t;
      C[a - 1][b - 1] = C[b - 1][a - 1] = c;
      T[a - 1][b - 1] = T[b - 1][a - 1] = t;
    }
    floyd(m, C, T);
    cin >> k;
    for (int i = 0; i < k; i++) {
      cin >> a >> b >> q;
      if (q)
        cout << T[a - 1][b - 1] << endl;
      else
        cout << C[a - 1][b - 1] << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#define MAX 1000000
using namespace std;
int main() {
  int n, m, a, b, cost, ti, k, p, q, r, point = 0;
  int cost_[101][101], time_[101][101], k_[101];
  for (int i = 0; i < 101; i++) {
    for (int l = 0; l < 101; l++) {
      cost_[i][l] = MAX;
      time_[i][l] = MAX;
    }
  }
  cin >> n >> m;
  while (n != 0 && m != 0) {
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> cost >> ti;
      cost_[a][b] = cost;
      time_[a][b] = ti;
    }
    cin >> k;
    for (int i = 0; i < k; i++) {
      cin >> p >> q >> r;
      k_[point] = p;
      k_[point + 1] = q;
      k_[point + 2] = r;
      point += 3;
    }
    point = 0;
    for (int i = 1; i <= m; i++) {
      for (int j = 1; j <= m; j++) {
        for (int o = 1; o <= m; o++) {
          if (cost_[j][i] != MAX && cost_[i][o] != MAX && time_[j][i] != MAX &&
              time_[i][o] != MAX) {
            cost_[j][o] = min(cost_[j][o], cost_[j][i] + cost_[i][o]);
            time_[j][o] = min(time_[j][o], time_[j][i] + time_[i][o]);
          }
        }
      }
    }
    for (int i = 0; i < k; i++) {
      if (k_[point + 2] == 0) {
        cout << cost_[k_[point]][k_[point + 1]] << endl;
      } else
        cout << time_[k_[point]][k_[point + 1]] << endl;
      point += 3;
    }
    point = 0;
    cin >> n >> m;
  }
  return 0;
}
Problem p00200 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    int d[2][101][101];
    REP(i, 2) REP(j, m + 1) REP(k, m + 1) { d[i][j][k] = (j == k ? 0 : 1e8); }
    int a, b, cost, time;
    REP(i, n) {
      cin >> a >> b >> cost >> time;
      d[0][a][b] = min(d[0][a][b], cost);
      d[0][b][a] = min(d[0][b][a], cost);
      d[1][a][b] = min(d[1][a][b], time);
      d[1][b][a] = min(d[1][b][a], time);
    }
    REP(k, m + 1) REP(i, m + 1) REP(j, m + 1) {
      d[0][i][j] = min(d[0][i][j], d[0][i][k] + d[0][k][j]);
      d[0][j][i] = min(d[0][j][i], d[0][j][k] + d[0][k][i]);
      d[1][i][j] = min(d[1][i][j], d[1][i][k] + d[1][k][j]);
      d[1][j][i] = min(d[1][j][i], d[1][j][k] + d[1][k][i]);
    }
    int k, p, q, r;
    cin >> k;
    REP(i, k) {
      cin >> p >> q >> r;
      cout << d[r][p][q] << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)

struct edge {
  int from, to, cost, time;
};

int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    vector<edge> edges;
    int a, b, v, u;
    REP(i, n) {
      cin >> a >> b >> v >> u;
      edges.push_back((edge){a, b, v, u});
    }
    int d[2][101][101];
    REP(i, 2) REP(j, m + 1) REP(k, m + 1) { d[i][j][k] = (j == k ? 0 : 1e8); }
    REP(i, m + 1) REP(j, m + 1) for (auto &e : edges) {
      d[0][j][e.to] = min(d[0][j][e.to], d[0][j][e.from] + e.cost);
      d[0][j][e.from] = min(d[0][j][e.from], d[0][j][e.to] + e.cost);
      d[1][j][e.to] = min(d[1][j][e.to], d[1][j][e.from] + e.time);
      d[1][j][e.from] = min(d[1][j][e.from], d[1][j][e.to] + e.time);
    }
    int k, p, q, r;
    cin >> k;
    REP(i, k) {
      cin >> p >> q >> r;
      cout << d[r][p][q] << endl;
    }
  }
  return 0;
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>

using namespace std;

int i, j, k, p, q, r, n, m, a, b, c, cost[101], t, dc[101][101], dt[101][101];

int dic(const int d[101][101]) {
  cost[p] = 0;
  int min, f[101] = {};
  for (i = 0; i < m; i++) {
    f[p] = 1;
    for (j = 0; j <= m; j++) {
      if (f[j])
        continue;
      if (cost[j] > cost[p] + d[p][j])
        cost[j] = cost[p] + d[p][j];
    }
    min = 200000000;
    for (j = 0; j <= m; j++) {
      if (f[j])
        continue;
      if (min > cost[j])
        min = cost[p = j];
    }
  }
  return cost[q];
}

int main() {
  while (cin >> n >> m, n != 0 || m != 0) {
    for (i = 0; i <= 100; i++)
      for (j = 0; j <= 100; j++) {
        dc[i][j] = 100000000;
        dt[i][j] = 100000000;
      }

    while (n--) {
      cin >> a >> b >> c >> t;
      dc[a][b] = dc[b][a] = c;
      dt[a][b] = dt[b][a] = t;
    }

    cin >> k;

    while (k--) {
      cin >> p >> q >> r;
      for (i = 0; i <= 100; i++)
        cost[i] = 100000000;
      if (r)
        cout << dic(dt) << endl;
      else
        cout << dic(dc) << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int i, j, k, p, q, r, n, m, a, b, c, cost[3001], t, dc[101][101], dt[101][101];

int dic(const int d[][101]) {
  cost[p] = 0;
  int min, f[3001] = {};
  for (i = 0; i < m; i++) {
    f[p] = 1;
    for (j = 1; j <= m; j++) {
      if (f[j])
        continue;
      if (cost[j] > cost[p] + d[p][j])
        cost[j] = cost[p] + d[p][j];
    }
    min = 200000000;
    for (j = 1; j <= m; j++) {
      if (f[j])
        continue;
      if (min > cost[j])
        min = cost[p = j];
    }
  }
  return cost[q];
}

int main() {
  for (i = 0; i < 100; i++)
    for (j = 0; j < 100; j++) {
      dc[i][j] = 100000000;
      dt[i][j] = 100000000;
    }

  cin >> n >> m;

  while (n--) {
    cin >> a >> b >> c >> t;
    dc[a][b] = dc[b][a] = c;
    dt[a][b] = dt[b][a] = t;
  }

  cin >> k;

  while (cin >> p >> q, p != 0 || q != 0) {
    cin >> r;
    for (i = 0; i <= 3000; i++)
      cost[i] = 100000000;
    if (r)
      cout << dic(dt) << endl;
    else
      cout << dic(dc) << endl;
  }

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

#include <algorithm>
#include <iostream>
const int INF = 1000000;
using namespace std;
int map[101][101][2]; // a, b, cost, time;
int d[101];           // 始点からの最短距離
bool used[101];       // 使われたかのフラグ
int V;                // 頂点数

int dijkstra(int start, int end, bool flag) {
  fill(d, d + V + 1, INF);
  fill(used, used + V + 1, false);
  d[start] = 0;

  while (1) {
    int v = -1;
    for (int u = 1; u <= V; u++) {
      if (!used[u] && (v == -1 || d[u] < d[v]))
        v = u;
    }

    if (v == -1)
      break;

    used[v] = true;

    for (int u = 1; u <= V; u++) {
      d[u] = min(d[u], d[v] + map[v][u][flag]);
    }
  }

  return d[end];
}

int main() {
  int n, m;
  while (cin >> n >> m, n) {
    V = m;

    for (int i = 0; i < 101; i++) {
      for (int j = 0; j < 101; j++) {
        map[i][j][0] = (map[i][j][1] = INF);
      }
    }

    for (int i = n; i; i--) {
      int a, b, cost, time;
      cin >> a >> b >> cost >> time;
      map[a][b][0] = cost;
      map[a][b][1] = time;
      map[b][a][0] = cost;
      map[b][a][1] = time;
    }

    int k;
    cin >> k;
    while (k--) {
      int p, q, r;
      cin >> p >> q >> r;
      cout << dijkstra(p, q, r) << '\\n';
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define INF 99999
int dijkstra(int x, int y, int p);
int D[110][110][2]; /*Adjacency matrix*/
int m;
int main() {
  while (1) {
    int n;
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (i == j) {
          D[i][j][0] = 0;
          D[i][j][1] = 0;
          continue;
        }
        D[i][j][0] = INF;
        D[i][j][1] = INF;
      }
    }

    for (int i = 0; i < n; i++) {
      int from, to, cst, tm;
      scanf("%d%d%d%d", &from, &to, &cst, &tm);
      D[from][to][0] = cst;
      D[to][from][0] = cst;
      D[from][to][1] = tm;
      D[to][from][1] = tm;
    }
    int k;
    scanf("%d", &k);
    for (int i = 0; i < k; i++) {
      int from, to, x;
      cin >> from >> to >> x;
      cout << dijkstra(from, to, x) << endl;
    }
  }
  return 0;
}
int dijkstra(int x, int y, int p) {
  int dist[128];
  bool done[128] = {false};
  for (int i = 1; i <= m; i++) {
    dist[i] = INF;
  }

  dist[x] = 0;
  int cost = 0;
  while (1) {
    int e = -1;
    for (int i = 1; i <= m; i++) {
      if (done[i] == false && (e == -1 || dist[i] < dist[e])) {
        e = i;
      }
    }
    if (e == -1)
      break;
    done[e] = true;
    if (e == y) {
      cost = dist[e];
      break;
    }

    for (int i = 1; i <= m; i++) {
      if (p == 0)
        dist[i] = min(dist[i], dist[e] + D[e][i][0]);
      else
        dist[i] = min(dist[i], dist[e] + D[e][i][1]);
    }
  }
  return cost;
}