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

#include <iostream>

using namespace std;

const int MAX_N = 110;
const int INF = 10000;
int d_cost[MAX_N][MAX_N];
int d_time[MAX_N][MAX_N];
int n, m;

void warshall_floyd(int d[MAX_N][MAX_N]) {
  for (int k = 0; k < m; k++)
    for (int i = 0; i < m; i++)
      for (int j = 0; j < m; j++)
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

int main() {
  while (cin >> n >> m, n || m) {
    int a, b, cost, time;
    int k, p, q, r;

    // 初期化
    for (int i = 0; i < m; i++)
      for (int j = 0; j < m; j++) {
        if (i == j)
          d_cost[i][j] = d_time[i][j] = 0;
        else
          d_cost[i][j] = d_time[i][j] = INF;
      }

    for (int i = 0; i < n; i++) {
      cin >> a >> b >> cost >> time;
      a--, b--;
      d_cost[a][b] = d_cost[b][a] = cost;
      d_time[a][b] = d_time[b][a] = time;
    }

    warshall_floyd(d_cost);
    warshall_floyd(d_time);

    cin >> k;
    for (int i = 0; i < k; i++) {
      cin >> p >> q >> r;

      p--, q--;
      if (r == 0)
        cout << d_cost[p][q] << endl;
      else
        cout << d_time[p][q] << endl;
    }
  }

  return 0;
}

Error: WA

Fixed submission:

#include <iostream>

using namespace std;

const int MAX_N = 110;
const int INF = 10000;
int d_cost[MAX_N][MAX_N];
int d_time[MAX_N][MAX_N];
int n, m;

void warshall_floyd(int d[MAX_N][MAX_N]) {
  for (int k = 0; k < m; k++)
    for (int i = 0; i < m; i++)
      for (int j = 0; j < m; j++)
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

int main() {
  while (cin >> n >> m, n || m) {
    int a, b, cost, time;
    int k, p, q, r;

    // 初期化
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) {
        if (i == j)
          d_cost[i][j] = d_time[i][j] = 0;
        else
          d_cost[i][j] = d_time[i][j] = INF;
      }

    for (int i = 0; i < n; i++) {
      cin >> a >> b >> cost >> time;
      a--, b--;
      d_cost[a][b] = d_cost[b][a] = cost;
      d_time[a][b] = d_time[b][a] = time;
    }
    //        warshall_floyd(d_cost);
    //        warshall_floyd(d_time);

    cin >> k;
    for (int i = 0; i < k; i++) {
      cin >> p >> q >> r;

      p--, q--;
      if (r == 0)
        cout << d_cost[p][q] << endl;
      else
        cout << d_time[p][q] << endl;
    }
  }

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

#include <iostream>

using namespace std;

const int inf = 1e8;

int d[201][201][2];
int E, V;

int main() {
  while (cin >> E >> V, E + V) {
    for (int i = 0; i < V; i++)
      for (int j = 0; j < V; j++) {
        d[i][j][0] = inf;
        d[i][j][1] = inf;
      }
    int s, t, c, ti;
    for (int i = 0; i < E; i++) {
      cin >> s >> t >> c >> ti;
      s--;
      t--;
      d[s][t][0] = c;
      d[s][t][1] = ti;

      d[t][s][0] = c;
      d[t][s][1] = ti;
    }

    for (int k = 0; k < V; k++) {
      for (int i = 0; i < V; i++) {
        for (int j = 0; j < V; j++) {
          d[i][j][1] = min(d[i][j][1], d[i][k][1] + d[k][j][1]);
          d[i][j][0] = min(d[i][j][0], d[i][k][0] + d[k][j][0]);
        }
      }
    }

    int num;
    cin >> num;
    for (int i = 0; i < num; i++) {
      int start, terminus, version;
      cin >> start >> terminus >> version;
      start--;
      terminus--;
      cout << (version ? d[start][terminus][1] : d[start][terminus][0]) << endl;
    }
  }
}

Error: 0

Fixed submission:

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

const int inf = 1e8;
int m, n;
// n経路の数（枝）　m駅の数（葉）
struct edge {
  int from, to, cost, time;
  edge(int from, int to, int cost, int time)
      : from(from), to(to), cost(cost), time(time) {}
};

vector<edge> es;
int shortest_path(int s, int e, int v) {
  int d[m];
  for (int i = 0; i < n; i++)
    d[i] = inf;
  d[s] = 0;
  while (true) {
    bool updata = false;
    for (int i = 0; i < n; i++) {
      edge e = es[i];
      if (d[e.from] != inf && d[e.to] > d[e.from] + e.cost && v == 0) {
        d[e.to] = d[e.from] + e.cost;
        updata = true;
      }

      if (d[e.from] != inf && d[e.to] > d[e.from] + e.time && v == 1) {
        d[e.to] = d[e.from] + e.time;
        updata = true;
      }
    }
    if (!updata)
      break;
  }
  return d[e];
}

int main(void) {
  while (cin >> n >> m, m + n) {
    es.clear();
    for (int i = 0; i < n; i++) {
      int s, t, c, ti;
      cin >> s >> t >> c >> ti;
      s--;
      t--;
      es.push_back(edge(s, t, c, ti));
    }
    int num;
    cin >> num;
    for (int i = 0; i < num; i++) {
      int s, t, v;
      cin >> s >> t >> v;
      s--;
      t--;
      // cout<<s <<" " << t << " " << v<<" ";
      cout << shortest_path(s, t, v) << endl;
    }
  }
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

#define min(x, y) ((x) < (y) ? (x) : (y))

int main(void) {
  int cost[100][100];
  int time[100][100];
  int n, m;
  int k;

  while (1) {
    for (int i = 0; i < 100; i++) {
      for (int j = 0; j < 100; j++) {
        cost[i][j] = time[i][j] = 100000000;
      }
    }

    scanf("%d %d", &n, &m);

    if (n == 0) {
      break;
    }

    for (int i = 0; i < n; i++) {
      int a, b, c, t;

      scanf("%d%d%d%d", &a, &b, &c, &t);
      a--;
      b--;
      cost[a][b] = cost[b][a] = min(cost[a][b], c);
      time[a][b] = time[b][a] = min(time[a][b], t);
    }

    for (int k = 0; k < m; k++) {
      for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++) {
          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]);
        }
      }
    }

    scanf("%d", &k);
    for (int i = 0; i < k; i++) {
      int a, b, r;

      scanf("%d%d%d", &a, &b, &r);

      a--;
      b--;

      if (r == 0) {
        printf("%d\\n", cost[a][b]);
      } else {
        printf("%d\\n", time[a][b]);
      }
    }
  }

  return (0);
}

Error: 0

Fixed submission:

#include <iostream>

#define INFINITY (1001)

using namespace std;

int main(void) {
  int time[300][300];
  int cost[300][300];
  int req[3][100];
  int n, m;
  while (1) {

    cin >> n >> m;
    if (n == 0 && m == 0) {
      break;
    }
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        time[i][j] = cost[i][j] = INFINITY;
      }
    }
    for (int i = 0; i < n; i++) {
      int a, b, t, c;
      cin >> a >> b >> c >> t;
      time[a - 1][b - 1] = time[b - 1][a - 1] = t;
      cost[a - 1][b - 1] = cost[b - 1][a - 1] = c;
    }

    for (int k = 0; k < m; k++) {
      for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++) {
          time[i][j] = min(time[i][j], time[i][k] + time[k][j]);
          cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
        }
      }
    }

    int req_count;
    cin >> req_count;
    for (int i = 0; i < req_count; i++) {
      cin >> req[0][i] >> req[1][i] >> req[2][i];
    }

    for (int i = 0; i < req_count; i++) {
      if (req[2][i] == 0) {
        cout << cost[req[0][i] - 1][req[1][i] - 1] << endl;
      } else {
        cout << time[req[0][i] - 1][req[1][i] - 1] << endl;
      }
    }
  }
  return (0);
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 114514810
#define ll long long
// #define scanf scanf_s

int main() {

  int cost[101][101];
  int time_[101][101];

  while (1) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    REP(i, 101) REP(j, 101) {
      if (i == j) {
        cost[i][j] = 0;
        time_[i][j] = 0;
      } else {
        cost[i][j] = INF;
        time_[i][j] = INF;
      }
    }

    REP(i, n) {
      int a, b, c, t;
      cin >> a >> b >> c >> t;
      a--;
      b--;
      cost[a][b] = cost[b][a] = c;
      time_[a][b] = 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: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 114514810
#define ll long long
// #define scanf scanf_s

int n, m, a, b, c, t, p, q, r;
int cost[101][101];
int time_[101][101];

int main() {

  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      return 0;
    REP(i, n) REP(j, n) {
      if (i == j) {
        cost[i][j] = 0;
        time_[i][j] = 0;
      } else {
        cost[i][j] = INF;
        time_[i][j] = INF;
      }
    }

    REP(i, n) {
      cin >> a >> b >> c >> t;
      a--;
      b--;
      cost[a][b] = cost[b][a] = c;
      time_[a][b] = time_[b][a] = t;
    }

    REP(i, m) REP(j, m) REP(k, 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 que;
    cin >> que;
    REP(i, que) {
      cin >> p >> q >> r;
      p--;
      q--;
      if (r == 0)
        cout << cost[p][q] << endl;
      else
        cout << time_[p][q] << endl;
    }
  }
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, m;
  while (cin >> n >> m, n != 0 && m != 0) {
    int cost[101][101];
    int time[101][101];
    for (int i = 0; i < 101; ++i) {
      for (int j = 0; j < 101; ++j)
        time[i][j] = cost[i][j] = (i == j) ? 0 : 100000000;
    }
    for (int i = 0; i < n; ++i) {
      int a, b, c, t;
      cin >> a >> b >> c >> t;
      cost[a][b] = c;
      cost[b][a] = c;
      time[a][b] = t;
      time[b][a] = t;
    }
    for (int i = 1; i <= m; ++i) {
      for (int j = 1; j <= m; ++j) {
        for (int k = 1; k <= m; ++k) {
          cost[j][k] = min(cost[j][k], cost[j][i] + cost[i][k]);
          time[j][k] = min(time[j][k], time[j][i] + time[i][k]);
        }
      }
    }
    int k;
    cin >> k;
    for (int i = 0; i < k; ++i) {
      int p, q, r;
      cin >> p >> q >> r;
      cout << ((r == 0) ? cost[p][q] : time[p][q]) << endl;
    }
  }
  return 0;
}

Error: -11

Fixed submission:

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

struct Node {
  vector<int> to;   // どのノードとつながっているか
  vector<int> cost; // エッジの料金
  vector<int> time; // エッジの時間

  bool done; // 確定ノードか
  int minCost;
  int from;
};

void addEdge(int v, int u, int c, int t, struct Node *node) {
  // uはvとつながっている
  node[u].to.push_back(v);
  // uとvのエッジのコスト
  node[u].cost.push_back(c);
  node[u].time.push_back(t);

  // 無向グラフの場合は以下の処理
  // ノードvはuとつながってる
  node[v].to.push_back(u);
  // uとvのエッジのコスト
  node[v].cost.push_back(c);
  node[v].time.push_back(t);
}

void dijkstra(int n, int start, int end, int k, struct Node *node) {
  for (int i = 0; i < n; ++i) {
    node[i].done = false;
    node[i].minCost = -1;
  }

  node[start].minCost = 0; // スタートまでのコストは0
  while (1) {
    int doneNode = -1; // 最新の確定したノード
    for (int i = 0; i < n; ++i) {
      if (node[i].done == true)
        continue; // i番目が確定ノードならcontinue
      if (node[i].minCost < 0)
        continue; // iまでのコストが不明の時continue
      // 確定ノードがないかiまでのコストのほうが小さい時最新の確定ノードを更新
      if (doneNode < 0 || node[i].minCost < node[doneNode].minCost)
        doneNode = i;
    }
    if (doneNode == -1)
      break;                    // 全ノードが確定したらbreak
    node[doneNode].done = true; // 確定ノードにする
    for (int i = 0; i < node[doneNode].to.size(); ++i) {
      int to = node[doneNode].to[i];
      int cost = node[doneNode].minCost +
                 (k == 0 ? node[doneNode].cost[i] : node[doneNode].time[i]);
      // toは未訪のノード
      // またはtoへより小さいコストの経路だったらtoの最小コストを更新
      if (node[to].minCost < 0 || cost < node[to].minCost) {
        node[to].minCost = cost;
        node[to].from = doneNode;
      }
    }
  }
}

int main() {
  int n, m;
  while (cin >> n >> m, n != 0 && m != 0) {
    struct Node node[m];
    for (int i = 0; i < n; ++i) {
      int a, b, cost, time;
      cin >> a >> b >> cost >> time;
      addEdge(a - 1, b - 1, cost, time, node);
    }
    int k;
    cin >> k;
    for (int i = 0; i < k; ++i) {
      int p, q, r;
      cin >> p >> q >> r;
      dijkstra(n, p - 1, q - 1, r, node);
      cout << node[q - 1].minCost << endl;
    }
  }
  return 0;
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int road1[111][111];
  int road2[111][111];
  int n, m;
  int a, b, cost, time;
  int p, q, r;
  int x;
  while (1) {
    for (int i = 0; i < 111; i++) {
      for (int j = 0; j < 111; j++) {
        road1[i][j] = road2[i][j] = 111111111;
      }
    }
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> cost >> time;
      road1[a][b] = road1[b][a] = cost;
      road2[a][b] = road2[b][a] = time;
    }

    for (int k = 1; k <= m; k++) {
      for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= m; j++) {
          if (road1[i][j] > road1[i][k] + road1[k][j]) {
            road1[i][j] = road1[i][k] + road1[k][j];
          }
          if (road2[i][j] > road2[i][k] + road2[k][j]) {
            road2[i][j] = road2[i][k] + road2[k][j];
          }
        }
      }
    }

    cin >> x;
    for (int i = 0; i < x; i++) {
      cin >> p >> q >> r;
      cout << (r == 0 ? road1[p][q] : road2[p][q]) << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int road1[111][111];
  int road2[111][111];
  int n, m;
  int a, b, cost, time;
  int p, q, r;
  int x;
  while (1) {
    for (int i = 0; i < 111; i++) {
      for (int j = 0; j < 111; j++) {
        road1[i][j] = road2[i][j] = 111111111;
      }
    }
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> cost >> time;
      road1[a][b] = road1[b][a] = cost;
      road2[a][b] = road2[b][a] = time;
    }

    for (int k = 1; k <= n; k++) {
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
          if (road1[i][j] > road1[i][k] + road1[k][j]) {
            road1[i][j] = road1[i][k] + road1[k][j];
          }
          if (road2[i][j] > road2[i][k] + road2[k][j]) {
            road2[i][j] = road2[i][k] + road2[k][j];
          }
        }
      }
    }

    cin >> x;
    for (int i = 0; i < x; i++) {
      cin >> p >> q >> r;
      cout << (r == 0 ? road1[p][q] : road2[p][q]) << endl;
    }
  }
}
Problem p00200 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define INF (10000000)
#define MAX (100)

using namespace std;

struct edge {
  int to, cost;
};
typedef pair<int, int> P;

vector<edge> T[MAX + 1], C[MAX + 1];
int dist[MAX + 1];

int dijkstra_c(int s, int g) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(dist, dist + MAX + 1, INF);
  dist[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (dist[v] < p.first)
      continue;
    for (int i = 0; i < C[v].size(); i++) {
      edge e = C[v][i];
      if (dist[e.to] > dist[v] + e.cost) {
        dist[e.to] = dist[v] + e.cost;
        que.push(P(dist[e.to], e.to));
      }
    }
  }
  return dist[g];
}

int dijkstra_t(int s, int g) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(dist, dist + MAX + 1, INF);
  dist[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (dist[v] < p.first)
      continue;
    for (int i = 0; i < T[v].size(); i++) {
      edge e = T[v][i];
      if (dist[e.to] > dist[v] + e.cost) {
        dist[e.to] = dist[v] + e.cost;
        que.push(P(dist[e.to], e.to));
      }
    }
  }
  return dist[g];
}

int main() {
  int n, m;
  while (cin >> n >> m && n) {
    for (int i = 0; i <= MAX; i++) {
      C[i].clear();
      T[i].clear();
    }

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

    int k, p, q, r;
    cin >> k;
    for (int i = 0; i < k; i++) {
      cin >> p >> q >> r;
      if (r == 0)
        cout << dijkstra_c(p, q) << endl;
      else
        cout << dijkstra_t(p, q) << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <vector>

#define INF 100000000

using namespace std;

int main() {
  int n, m;
  while (true) {
    cin >> n >> m;
    if (n == 0 || m == 0)
      break;
    int times[n + 1][n + 1], costs[n + 1][n + 1];
    int a, b, cost, time;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        times[i][j] = costs[i][j] = (i == j) ? 0 : INF;

    for (int i = 0; i < n; i++) {
      cin >> a >> b >> cost >> time;
      costs[a][b] = costs[b][a] = cost;
      times[a][b] = times[b][a] = time;
    }

    for (int a = 1; a <= n; a++) {
      for (int b = 1; b <= n; b++) {
        for (int c = 1; c <= n; c++) {
          times[a][b] = min(times[a][b], times[a][c] + times[c][b]);
          costs[a][b] = min(costs[a][b], costs[a][c] + costs[c][b]);
        }
      }
    }

    int p, q, r, qn;
    cin >> qn;
    for (int i = 0; i < qn; i++) {
      cin >> p >> q >> r;
      if (r == 1)
        cout << times[p][q] << endl;
      else
        cout << costs[p][q] << endl;
    }
  }
  return 0;
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, m;
  int a, b, c, d;
  int x;
  int p, q, r;
  int cost[111][111];
  int time[111][111];
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < 111; i++) {
      for (int j = 0; j < 111; j++) {
        cost[i][j] = 9999999;
        time[i][j] = 9999999;
      }
    }
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> c >> d;
      cost[a - 1][b - 1] = cost[b - 1][a - 1] = c;
      time[a - 1][b - 1] = time[b - 1][a - 1] = d;
    }
    for (int k = 0; k < m; k++) {
      for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++) {
          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]);
        }
      }
    }
    cin >> x;
    for (int i = 0; i < x; i++) {
      cin >> p >> q >> r;
      cout << (r == 0 ? cost[p - 1][q - 1] : time[p - 1][q - 1]) << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, m;
  int a, b, c, d;
  int x;
  int p, q, r;
  int cost[111][111];
  int time[111][111];
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < 111; i++) {
      for (int j = 0; j < 111; j++) {
        cost[i][j] = 9999999;
        time[i][j] = 9999999;
      }
    }
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> c >> d;
      cost[a][b] = cost[b][a] = c;
      time[a][b] = time[b][a] = d;
    }
    for (int k = 0; k < n; k++) {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          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]);
        }
      }
    }
    cin >> x;
    for (int i = 0; i < x; i++) {
      cin >> p >> q >> r;
      cout << (r == 0 ? cost[p][q] : time[p][q]) << endl;
    }
  }
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int road1[111][111];
  int road2[111][111];
  int n, m;
  int a, b, cost, time;
  int p, q, r;
  int x;
  while (1) {
    for (int i = 0; i < 111; i++) {
      for (int j = 0; j < 111; j++) {
        road1[i][j] = road2[i][j] = 111111111;
      }
    }
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> cost >> time;
      road1[a][b] = road1[b][a] = cost;
      road2[a][b] = road2[b][a] = time;
    }

    for (int k = 1; k <= m; k++) {
      for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= m; j++) {
          if (road1[i][j] > road1[i][k] + road1[k][j]) {
            road1[i][j] = road1[i][k] + road1[k][j];
          }
          if (road2[i][j] > road2[i][k] + road2[k][j]) {
            road2[i][j] = road2[i][k] + road2[k][j];
          }
        }
      }
    }

    cin >> x;
    for (int i = 0; i < x; i++) {
      cin >> p >> q >> r;
      cout << (r == 0 ? road1[p][q] : road2[p][q]) << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, m;
  int a, b, c, d;
  int x;
  int p, q, r;
  int cost[111][111];
  int time[111][111];
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < 111; i++) {
      for (int j = 0; j < 111; j++) {
        cost[i][j] = 9999999;
        time[i][j] = 9999999;
      }
    }
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> c >> d;
      cost[a - 1][b - 1] = c;
      cost[b - 1][a - 1] = c;
      time[a - 1][b - 1] = d;
      time[b - 1][a - 1] = d;
    }
    for (int k = 0; k < n; k++) {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          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]);
        }
      }
    }
    cin >> x;
    for (int i = 0; i < x; i++) {
      cin >> p >> q >> r;
      cout << (r == 0 ? cost[p - 1][q - 1] : time[p - 1][q - 1]) << endl;
    }
  }
}