alexjercan/bugnet huggingface dataset:
Problem p00200 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m, n) {
    int a, b, c, d;
    int co[m][m];
    int ti[m][m];
    for (int i = 0; i < m; i++)
      for (int j = 0; j < m; j++) {
        co[i][j] = 100000000;
        ti[i][j] = 100000000;
      }
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> c >> d;
      a--;
      b--;
      co[a][b] = c;
      co[b][a] = c;
      ti[a][b] = d;
      ti[b][a] = d;
    }
    int asd, p, q, r;
    cin >> asd;
    for (int l = 0; l < m; l++)
      for (int j = 0; j < m; j++)
        for (int k = 0; k < m; k++) {
          co[j][k] = min(co[j][k], co[j][l] + co[l][k]);
          ti[j][k] = min(ti[j][k], ti[j][l] + ti[l][k]);
        }
    for (int i = 0; i < asd; i++) {
      cin >> p >> q >> r;
      p--;
      q--;
      cout << (r == 0 ? co[p][q] : ti[p][q]) << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m, n) {
    int a, b, c, d;
    int co[m][m];
    int ti[m][m];
    for (int i = 0; i < m; i++)
      for (int j = 0; j < m; j++) {
        co[i][j] = 100000000;
        ti[i][j] = 100000000;
      }
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> c >> d;
      a--;
      b--;
      co[a][b] = c;
      co[b][a] = c;
      ti[a][b] = d;
      ti[b][a] = d;
    }
    int k, p, q, r;
    cin >> k;
    for (int i = 0; i < k; i++) {
      cin >> p >> q >> r;
      p--;
      q--;
      for (int l = 0; l < m; l++)
        for (int j = 0; j < m; j++)
          for (int k = 0; k < m; k++) {
            if (r == 0)
              co[j][k] = min(co[j][k], co[j][l] + co[l][k]);
            else
              ti[j][k] = min(ti[j][k], ti[j][l] + ti[l][k]);
          }
      cout << (r == 0 ? co[p][q] : ti[p][q]) << endl;
    }
  }
  return 0;
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  const int MAX = 1e5;
  for (int n, m; cin >> n >> m, n;) {
    int cost[m][m];
    int time[m][m];
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        cost[i][j] = MAX;
        time[i][j] = MAX;
      }
    }
    int a, b, c, t;
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> c >> t;
      cost[a - 1][b - 1] = c;
      cost[b - 1][a - 1] = c;
      time[a - 1][b - 1] = t;
      time[b - 1][a - 1] = t;
    }
    for (int k = 0; k < m; k++) {
      for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++) {
          if (cost[i][j] > cost[i][k] + cost[k][j])
            cost[i][j] = cost[i][k] + cost[k][j];
          if (time[i][j] > time[i][k] + time[k][j])
            time[i][j] = time[i][k] + time[k][j];
        }
      }
    }
    int l, r;
    cin >> l;
    for (int i = 0; i < l; i++) {
      cin >> a >> b >> r;
      if (r)
        cout << time[a - 1][b - 1] << endl;
      else
        cout << cost[a - 1][b - 1] << endl;
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  const int MAX = 1e5;
  for (int n, m; cin >> n >> m, n;) {
    int cost[m][m];
    int time[m][m];
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        cost[i][j] = MAX;
        time[i][j] = MAX;
      }
    }
    int a, b, c, t;
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> c >> t;
      cost[a - 1][b - 1] = c;
      cost[b - 1][a - 1] = c;
      time[a - 1][b - 1] = t;
      time[b - 1][a - 1] = t;
    }
    for (int k = 0; k < m; k++) {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          if (cost[i][j] > cost[i][k] + cost[k][j])
            cost[i][j] = cost[i][k] + cost[k][j];
          if (time[i][j] > time[i][k] + time[k][j])
            time[i][j] = time[i][k] + time[k][j];
        }
      }
    }
    int l, r;
    cin >> l;
    for (int i = 0; i < l; i++) {
      cin >> a >> b >> r;
      if (r)
        cout << time[a - 1][b - 1] << endl;
      else
        cout << cost[a - 1][b - 1] << endl;
    }
  }
  return 0;
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  const int MAX = 1e5;
  for (int n, m; cin >> n >> m, n;) {
    int cost[m][m];
    int time[m][m];
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        cost[i][j] = MAX;
        time[i][j] = MAX;
      }
    }
    int a, b, c, t;
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> c >> t;
      cost[max(a - 1, b - 1)][min(a - 1, b - 1)] = c;
      time[max(a - 1, b - 1)][min(a - 1, b - 1)] = t;
    }
    for (int k = 0; k < m; k++) {
      for (int i = 0; i < m; i++) {
        for (int j = 0; j <= i; j++) {
          int mai = max(i, k), mii = min(i, k);
          int maj = max(j, k), mij = min(j, k);
          if (cost[i][j] > cost[mai][mii] + cost[maj][mij])
            cost[i][j] = cost[mai][mii] + cost[maj][mij];
          if (time[i][j] > time[mai][mii] + time[maj][mij])
            time[i][j] = time[mai][mii] + time[maj][mij];
        }
      }
    }
    int l, r;
    cin >> l;
    for (int i = 0; i < l; i++) {
      cin >> a >> b >> r;
      if (r)
        cout << time[max(a - 1, b - 1)][min(a - 1, b - 1)] << endl;
      else
        cout << cost[max(a - 1, b - 1)][min(a - 1, b - 1)] << endl;
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  const int MAX = 1e5;
  for (int n, m; cin >> n >> m, n;) {
    int cost[m][m];
    int time[m][m];
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        cost[i][j] = MAX;
        time[i][j] = MAX;
      }
    }
    int a, b, c, t;
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> c >> t;
      cost[max(a - 1, b - 1)][min(a - 1, b - 1)] = c;
      time[max(a - 1, b - 1)][min(a - 1, b - 1)] = t;
    }
    for (int k = 0; k < m; k++) {
      for (int i = 0; i <= m; i++) {
        for (int j = 0; j <= i; j++) {
          int mai = max(i, k), mii = min(i, k);
          int maj = max(j, k), mij = min(j, k);
          if (cost[i][j] > cost[mai][mii] + cost[maj][mij])
            cost[i][j] = cost[mai][mii] + cost[maj][mij];
          if (time[i][j] > time[mai][mii] + time[maj][mij])
            time[i][j] = time[mai][mii] + time[maj][mij];
        }
      }
    }
    int l, r;
    cin >> l;
    for (int i = 0; i < l; i++) {
      cin >> a >> b >> r;
      if (r)
        cout << time[max(a - 1, b - 1)][min(a - 1, b - 1)] << endl;
      else
        cout << cost[max(a - 1, b - 1)][min(a - 1, b - 1)] << endl;
    }
  }
  return 0;
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#define INF 10000000

int main(void) {
  int n, m;

  while (scanf("%d %d", &m, &n), n, m) {
    int i, j;
    int a, b, cost, time, c;
    int DPc[256][256];
    int DPt[256][256];
    int k, ans[256];

    for (i = 0; i < 256; i++) {
      for (j = 0; j < 256; j++) {
        if (i == j) {
          DPc[i][j] = 0;
          DPt[i][j] = 0;
        } else {
          DPc[i][j] = INF;
          DPt[i][j] = INF;
        }
      }
    }

    for (i = 0; i < m; i++) {
      scanf("%d %d %d %d", &a, &b, &cost, &time);
      DPc[a][b] = cost;
      DPc[b][a] = cost;
      DPt[a][b] = time;
      DPt[b][a] = time;
    }

    for (k = 0; k <= n; k++) {
      for (i = 0; i <= n; i++) {
        for (j = 0; j <= n; j++) {
          if (DPt[i][k] + DPt[k][j] < DPt[i][j]) {
            DPt[i][j] = DPt[i][k] + DPt[k][j];
          }
          if (DPc[i][k] + DPc[k][j] < DPc[i][j]) {
            DPc[i][j] = DPc[i][k] + DPc[k][j];
          }
        }
      }
    }

    scanf("%d", &m);
    for (i = 0; i < m; i++) {
      scanf("%d %d %d", &a, &b, &c);
      if (c == 1) {
        ans[i] = DPt[a][b];
      } else {
        ans[i] = DPc[a][b];
      }
    }
    for (i = 0; i < m; i++) {
      printf("%d\\n", ans[i]);
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
#define INF 100000000

int main(void) {
  int n, m;

  while (scanf("%d%d", &m, &n), n, m) {
    int i, j;
    int a, b, cost, time, c;
    int DPc[256][256];
    int DPt[267][256];
    int k, ans[128], count = 0;

    for (i = 0; i < 128; i++) {
      for (j = 0; j < 128; j++) {
        if (i == j) {
          DPc[i][j] = 0;
          DPt[i][j] = 0;
        } else {
          DPc[i][j] = INF;
          DPt[i][j] = INF;
        }
      }
    }

    for (i = 0; i < m; i++) {
      scanf("%d%d%d%d", &a, &b, &cost, &time);
      DPc[a][b] = cost;
      DPc[b][a] = cost;
      DPt[a][b] = time;
      DPt[b][a] = time;
    }
    for (i = 0; i <= n; i++) {
      for (j = 0; j <= n; j++) {
        for (k = 0; k <= n; k++) {
          if (DPt[i][k] + DPt[k][j] < DPt[i][j]) {
            DPt[i][j] = DPt[i][k] + DPt[k][j];
          }
          if (DPc[i][k] + DPc[k][j] < DPc[i][j]) {
            DPc[i][j] = DPc[i][k] + DPc[k][j];
          }
        }
      }
    }

    scanf("%d", &m);
    for (i = 0; i < m; i++) {
      scanf("%d%d%d", &a, &b, &c);
      if (c == 1) {
        ans[count] = DPt[a][b];
      } else {
        ans[count] = DPc[a][b];
      }
      count++;
    }
    for (i = 0; i < m; i++) {
      printf("%d\\n", ans[i]);
    }
  }
  return 0;
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <time.h>
#include <vector>
using namespace std;
clock_t fi, endtime;

const int INF = 100 * 6001;
const int r_c = 0;
const int r_t = 1;
const int MAX_V = 100;
const int MAX_E = 6000;

int main() {
  while (1) {
    int n, m, a, b, c, t;
    int k, p, q, r;

    int wft[MAX_V][MAX_V];
    int wfc[MAX_V][MAX_V];

    scanf("%d %d", &n, &m);
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < m; ++i) {
      for (int j = 0; j < m; ++j) {
        wfc[i][j] = INF;
        wft[i][j] = INF;
      }
    }
    for (int i = 0; i < n; ++i) {
      scanf("%d %d %d %d", &a, &b, &c, &t);
      wft[a - 1][b - 1] = t;
      wft[b - 1][a - 1] = t;
      wfc[a - 1][b - 1] = c;
      wfc[b - 1][a - 1] = c;
    }
    for (int l = 0; l < m; ++l) {
      for (int i = 0; i < m; ++i) {
        for (int j = 0; j < m; ++j) {
          if (wft[i][j] > wft[i][l] + wft[l][j]) {
            wft[i][j] = wft[i][l] + wft[l][j];
          }
          if (wfc[i][j] > wfc[i][l] + wfc[l][j]) {
            wfc[i][j] = wfc[i][l] + wfc[l][j];
          }
        }
      }
    }
    scanf("%d", &k);
    int ans = 0;
    for (int i = 0; i < k; ++i) {
      scanf("%d %d %d", &p, &q, &r);
      if (r == 0) {
        ans = wfc[p - 1][q - 1];
      } else {
        ans = wft[p - 1][q - 1];
      }
      printf("%d\\n", ans);
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <time.h>
#include <vector>
using namespace std;

const int INF = 100 * 1000 + 2;
const int r_c = 0;
const int r_t = 1;
const int MAX_V = 100;
const int MAX_E = 6000;

int n, m, a, b, c, t;
int k, p, q, r;
int wf[MAX_V][2] = {0};

struct edge {
  int from, to, ct[2];
};
edge edg[MAX_E];

int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i <= m * 2; ++i) {
    scanf("%d %d %d %d", &a, &b, &c, &t);
    edg[i].from = a - 1;
    edg[i].to = b - 1;
    edg[i].ct[r_c] = c;
    edg[i].ct[r_t] = t;
    ++i;
    edg[i].from = b - 1;
    edg[i].to = a - 1;
    edg[i].ct[r_c] = c;
    edg[i].ct[r_t] = t;
  }
  scanf("%d", &k);
  for (int i = 0; i < k; ++i) {
    scanf("%d %d %d", &p, &q, &r);
    for (int i = 0; i < n; ++i) {
      wf[i][r] = INF;
    }
    wf[p - 1][r] = 0;
    while (1) {
      bool bo = false;
      for (int i = 0; i < m * 2; ++i) {
        edge e = edg[i];
        if (wf[e.from][r] != INF && wf[e.to][r] > wf[e.from][r] + e.ct[r]) {
          wf[e.to][r] = wf[e.from][r] + e.ct[r];
          bo = true;
        }
      }
      if (!bo)
        break;
    }
    if (wf[q - 1][r] == INF)
      printf("INF\\n");
    else
      printf("%d\\n", wf[q - 1][r]);
  }
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

#define INF 100000;
using namespace std;

int main() {
  int n, m;
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0) {
      break;
    }
    int s_tim[m][m];
    int c_money[m][m];
    int a, b, cost, tim;

    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        s_tim[i][j] = INF;
        c_money[i][j] = INF;
      }
    }
    for (int i = 0; i < m; i++) {
      s_tim[i][i] = 0;
      c_money[i][i] = 0;
    }
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> cost >> tim;
      s_tim[a - 1][b - 1] = tim;
      s_tim[b - 1][a - 1] = tim;
      c_money[a - 1][b - 1] = cost;
      c_money[b - 1][a - 1] = cost;
    }

    for (int k = 0; k < m; k++) {
      for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++) {
          if (s_tim[i][j] > s_tim[i][k] + s_tim[k][j]) {
            s_tim[i][j] = s_tim[i][k] + s_tim[k][j];
          }
          if (c_money[i][j] > c_money[i][k] + c_money[k][j]) {
            c_money[i][j] = c_money[i][k] + c_money[k][j];
          }
        }
      }
    }

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

    for (int i = 0; i < contacts; i++) {
      cin >> p >> q >> r;
      if (r) {
        cout << s_tim[p - 1][q - 1];
      } else {
        cout << c_money[p - 1][q - 1];
      }
      cout << endl;
    }
  }
}


Error: 0

Fixed submission:

#include <iostream>

#define INF 1000000;
using namespace std;

int main() {
  int n, m;
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0) {
      break;
    }
    int s_tim[m][m];
    int c_money[m][m];
    int a, b, cost, tim;

    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        s_tim[i][j] = INF;
        c_money[i][j] = INF;
      }
    }
    for (int i = 0; i < m; i++) {
      s_tim[i][i] = 0;
      c_money[i][i] = 0;
    }
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> cost >> tim;
      s_tim[a - 1][b - 1] = tim;
      s_tim[b - 1][a - 1] = tim;
      c_money[a - 1][b - 1] = cost;
      c_money[b - 1][a - 1] = cost;
    }

    for (int k = 0; k < m; k++) {
      for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++) {
          if (s_tim[i][j] > s_tim[i][k] + s_tim[k][j]) {
            s_tim[i][j] = s_tim[i][k] + s_tim[k][j];
          }
          if (c_money[i][j] > c_money[i][k] + c_money[k][j]) {
            c_money[i][j] = c_money[i][k] + c_money[k][j];
          }
        }
      }
    }

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

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

#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
static const int INFTY = (1 << 21);
int main() {
  int n, m, a, b, cost, time;
  int kk, p, q, r;
  int sta_c[101][101];
  int sta_t[101][101];
  while (cin >> n >> m, n, m) {
    for (int i = 0; i < 101; i++) {
      for (int j = 0; j < 101; j++) {
        sta_c[i][j] = sta_t[i][j] = INFTY;
      }
    }
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> cost >> time;
      sta_c[a][b] = cost;
      sta_c[b][a] = cost;
      sta_t[a][b] = time;
      sta_t[b][a] = time;
    }
    for (int k = 1; k <= m; k++) {
      for (int i = 1; i <= m; i++) {
        if (sta_c[i][k] == INFTY)
          continue;
        for (int j = 1; j <= m; j++) {
          if (sta_c[k][j] == INFTY)
            continue;
          sta_c[i][j] = min(sta_c[i][j], sta_c[i][k] + sta_c[k][j]);
          sta_t[i][j] = min(sta_t[i][j], sta_t[i][k] + sta_t[k][j]);
        }
      }
    }
    cin >> kk;
    for (int i = 0; i < kk; i++) {
      cin >> p >> q >> r;
      if (r == 0)
        cout << sta_c[p][q] << endl;
      else
        cout << sta_t[p][q] << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
static const int INFTY = (1 << 21);
int main() {
  int n, m, a, b, cost, time;
  int kk, p, q, r;
  int sta_c[100][100];
  int sta_t[100][100];
  while (cin >> n >> m, n, m) {
    for (int i = 0; i < 100; i++) {
      for (int j = 0; j < 100; j++) {
        sta_c[i][j] = sta_t[i][j] = INFTY;
      }
    }
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> cost >> time;
      sta_c[a][b] = cost;
      sta_c[b][a] = cost;
      sta_t[a][b] = time;
      sta_t[b][a] = time;
    }
    for (int k = 1; k <= m; k++) {
      for (int i = 1; i <= m; i++) {
        if (sta_c[i][k] == INFTY)
          continue;
        for (int j = 1; j <= m; j++) {
          if (sta_c[k][j] == INFTY)
            continue;
          sta_c[i][j] = min(sta_c[i][j], sta_c[i][k] + sta_c[k][j]);
          sta_t[i][j] = min(sta_t[i][j], sta_t[i][k] + sta_t[k][j]);
        }
      }
    }
    cin >> kk;
    for (int i = 0; i < kk; i++) {
      cin >> p >> q >> r;
      if (r == 0)
        cout << sta_c[p][q] << endl;
      else
        cout << sta_t[p][q] << endl;
    }
  }
  return 0;
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, x, n) for (int i = x; i < n; i++)
#define pf push_front
#define pb push_back
#define int long long
using namespace std;
const int INF = 1000000007;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int N = 101;

int cost[N][N];
int tim[N][N];

int bfs(int n, int p, int q, int graph[N][N]) {
  vector<int> v(n);
  queue<int> que;
  rep(i, n) v[i] = INF;
  v[p] = 0;
  que.push(p);
  int u;
  while (!que.empty()) {
    u = que.front(), que.pop();

    rep(i, n) {
      if (v[i] > v[u] + graph[u][i]) {
        v[i] = v[u] + graph[u][i];
        que.push(i);
      }
    }
  }
  return v[q];
}

signed main() {
  int n, m;
  while (cin >> n >> m, n != 0) {
    rep(i, m) rep(j, m) {
      cost[i][j] = (i == j ? 0 : INF);
      tim[i][j] = (i == j ? 0 : INF);
    }
    rep(i, n) {
      int a, b, c, t;
      cin >> a >> b >> c >> t;
      a--;
      b--;
      cost[a][b] = cost[b][a] = c;
      tim[a][b] = tim[b][a] = t;
    }
    int k;
    cin >> k;
    rep(i, k) {
      int p, q, r;
      cin >> p >> q >> r;
      p--;
      q--;
      int ans;
      if (r == 0) {
        ans = bfs(m, p, q, cost);
      } else {
        ans = bfs(m, p, q, tim);
      }
      cout << ans << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, x, n) for (int i = x; i < n; i++)
#define pf push_front
#define pb push_back
#define int long long
using namespace std;
const int INF = 1000000007;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int N = 101;

int cost[N][N];
int tim[N][N];

int bfs(int n, int p, int q, int graph[N][N]) {
  vector<int> v(n);
  queue<int> que;
  rep(i, n) v[i] = INF;
  v[p] = 0;
  que.push(p);
  int u;
  while (!que.empty()) {
    u = que.front(), que.pop();

    rep(i, n) {
      if (v[i] > v[u] + graph[u][i]) {
        v[i] = v[u] + graph[u][i];
        que.push(i);
      }
    }
  }
  return v[q];
}

signed main() {
  int n, m;
  while (cin >> n >> m, n != 0) {
    rep(i, n) rep(j, n) {
      cost[i][j] = (i == j ? 0 : INF);
      tim[i][j] = (i == j ? 0 : INF);
    }
    rep(i, n) {
      int a, b, c, t;
      cin >> a >> b >> c >> t;
      a--;
      b--;
      cost[a][b] = cost[b][a] = c;
      tim[a][b] = tim[b][a] = t;
    }
    int k;
    cin >> k;
    rep(i, k) {
      int p, q, r;
      cin >> p >> q >> r;
      p--;
      q--;
      int ans;
      if (r == 0) {
        ans = bfs(n, p, q, cost);
      } else {
        ans = bfs(n, p, q, tim);
      }
      cout << ans << endl;
    }
  }

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

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < s; i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
signed main() {
  while (1) {
    int n, m;
    cin >> n >> m;
    if (!(n + m))
      break;
    vector<vector<pii>> v(m + 1, vector<pii>(m + 1, pii(INF, INF)));
    rep(i, m + 1) v[i][i] = pii(0, 0);
    rep(i, n) {
      pii temp;
      int s, g;
      cin >> s >> g >> temp.first >> temp.second;
      v[--s][--g] = temp;
    }
    n = m;
    rep(k, n) {
      rep(i, n) {
        rep(j, n) {
          v[i][j].first = min(v[i][k].first + v[k][j].first, v[i][j].first);
          v[i][j].second = min(v[i][k].second + v[k][j].second, v[i][j].second);
          v[j][i] = v[i][j];
        }
      }
    }
    int k;
    cin >> k;
    rep(i, k) {
      int s, g, r;
      cin >> s >> g >> r;
      if (!r)
        cout << v[--s][--g].first << endl;
      else
        cout << v[--s][--g].second << endl;
    }
  }
}


Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < s; i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
signed main() {
  while (1) {
    int n, m;
    cin >> n >> m;
    if (!(n + m))
      break;
    vector<vector<pii>> v(m + 1, vector<pii>(m + 1, pii(INF, INF)));
    rep(i, n + 1) v[i][i] = pii(0, 0);
    rep(i, n) {
      pii temp;
      int s, g;
      cin >> s >> g >> temp.first >> temp.second;
      v[--s][--g] = temp;
    }
    n = m;
    rep(k, n) {
      rep(i, n) {
        rep(j, n) {
          v[i][j].first = min(v[i][k].first + v[k][j].first, v[i][j].first);
          v[i][j].second = min(v[i][k].second + v[k][j].second, v[i][j].second);
        }
      }
    }
    int k;
    cin >> k;
    rep(i, k) {
      int s, g, r;
      cin >> s >> g >> r;
      if (!r)
        cout << v[--s][--g].first << endl;
      else
        cout << v[--s][--g].second << endl;
    }
  }
}