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

#include <algorithm>
#include <cstdio>
#include <cstring>
#define INF (1145141919)
using namespace std;

int n;

int from[6000];
int to[6000];
int cost[6000][2];

int d[100];
int r;
void Search(int s) {
  for (int i = 0; i < 100; i++) {
    d[i] = INF;
  }
  d[s] = 0;

  while (true) {
    bool update = false;

    for (int i = 0; i < n * 2; i++) {
      if (d[from[i]] != INF && d[to[i]] > d[from[i]] + cost[i][r]) {
        d[to[i]] = d[from[i]] + cost[i][r];
        update = true;
      }
    }

    if (!update) {
      break;
    }
  }
}

int main() {
  int m;
  while (scanf("%d %d", &n, &m), n + m) {
    for (int i = 0; i < n; i++) {
      int a, b, c, t;
      scanf("%d %d %d %d", &a, &b, &c, &t);
      a--;
      b--;

      from[i * 2] = a;
      to[i * 2] = b;
      cost[i * 2][0] = c;
      cost[i * 2][1] = t;

      from[i * 2 + 1] = b;
      to[i * 2 + 1] = a;
      cost[i * 2 + 1][0] = c;
      cost[i * 2 + 1][1] = t;
    }

    int k;
    scanf("%d", &k);

    for (int i = 0; i < k; i++) {
      int p, q;
      scanf("%d %d %d", &p, &q, &r);
      p--;
      q--;

      Search(p);
      printf("%d\\n", d[q]);
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#define INF (1145141919)
using namespace std;

int n;

int from[3000];
int to[3000];
int cost[3000][2];

int d[100];
int r;
void Search(int s) {
  for (int i = 0; i < 100; i++) {
    d[i] = INF;
  }
  d[s] = 0;

  while (true) {
    bool update = false;

    for (int i = 0; i < n * 2; i++) {
      if (d[from[i]] != INF && d[to[i]] > d[from[i]] + cost[i][r]) {
        d[to[i]] = d[from[i]] + cost[i][r];
        update = true;
      }
    }

    if (!update) {
      break;
    }
  }
}

int main() {
  int m;
  while (scanf("%d %d", &n, &m), n + m) {
    for (int i = 0; i < n; i++) {
      int a, b, c, t;
      scanf("%d %d %d %d", &a, &b, &c, &t);
      a--;
      b--;

      from[i * 2] = a;
      to[i * 2] = b;
      cost[i * 2][0] = c;
      cost[i * 2][1] = t;

      from[i * 2 + 1] = b;
      to[i * 2 + 1] = a;
      cost[i * 2 + 1][0] = c;
      cost[i * 2 + 1][1] = t;
    }

    int k;
    scanf("%d", &k);

    for (int i = 0; i < k; i++) {
      int p, q;
      scanf("%d %d %d", &p, &q, &r);
      p--;
      q--;

      Search(p);
      printf("%d\\n", d[q]);
    }
  }

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

#include <iostream>
using namespace std;
int MAX = 100000;
int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (!n && !m)
      break;
    int a, b, cost, timer;
    int costs[m][m];
    int timers[m][m];
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        costs[i][j] = MAX;
        timers[i][j] = MAX;
      }
      costs[i][i] = 0;
      timers[i][i] = 0;
    }

    for (int i = 0; i < n; i++) {
      cin >> a >> b >> cost >> timer;
      costs[a - 1][b - 1] = cost;
      timers[a - 1][b - 1] = timer;
      costs[b - 1][a - 1] = cost;
      timers[b - 1][a - 1] = timer;
    }
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        for (int k = 0; k < m; k++) {
          if (costs[j][k] > (costs[j][i] + costs[i][k])) {
            costs[j][k] = costs[j][i] + costs[i][k];
            costs[k][j] = costs[j][i] + costs[i][k];
          }
          if (timers[j][k] > (timers[j][i] + timers[i][k])) {
            timers[j][k] = timers[j][i] + timers[i][k];
            timers[k][j] = timers[j][i] + timers[i][k];
          }
        }
      }
    }
    int k;
    int p;
    int q;
    bool r;
    cin >> k;
    for (int i = 0; i < k; i++) {
      cin >> p >> q >> r;
      if (r) {
        cout << timers[p - 1][q - 1] << endl;
      } else if (!r) {
        cout << costs[p - 1][q - 1] << endl;
      }
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int MAX = 100000;
int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    int a, b, cost, timer;
    int costs[m][m];
    int timers[m][m];
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        costs[i][j] = MAX;
        timers[i][j] = MAX;
      }
      costs[i][i] = 0;
      timers[i][i] = 0;
    }

    for (int i = 0; i < n; i++) {
      cin >> a >> b >> cost >> timer;
      costs[a - 1][b - 1] = cost;
      timers[a - 1][b - 1] = timer;
      costs[b - 1][a - 1] = cost;
      timers[b - 1][a - 1] = timer;
    }
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        for (int k = 0; k < m; k++) {
          if (costs[j][k] > (costs[j][i] + costs[i][k])) {
            costs[j][k] = costs[j][i] + costs[i][k];
            costs[k][j] = costs[j][i] + costs[i][k];
          }
          if (timers[j][k] > (timers[j][i] + timers[i][k])) {
            timers[j][k] = timers[j][i] + timers[i][k];
            timers[k][j] = timers[j][i] + timers[i][k];
          }
        }
      }
    }
    int k;
    int p;
    int q;
    bool r;
    cin >> k;
    for (int i = 0; i < k; i++) {
      cin >> p >> q >> r;
      if (r) {
        cout << timers[p - 1][q - 1] << endl;
      } else if (!r) {
        cout << costs[p - 1][q - 1] << endl;
      }
    }
  }
  return 0;
}
Problem p00200 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int i, j, k;
  int c[100][100], t[100][100], m, n, o;
  while (cin >> n >> m && n + m) {
    for (i = 0; i < m; i++) {
      for (j = 0; j < m; j++) {
        c[i][j] = 10000;
        t[i][j] = 10000;
      }
    }
    for (i = 0; i < n; i++) {
      int p, q, r, s;
      cin >> p >> q >> r >> s;
      p--;
      q--;
      c[p][q] = min(c[p][q], r);
      c[q][p] = c[p][q];
      t[p][q] = min(t[p][q], s);
      t[q][p] = t[p][q];
    }
    for (k = 0; k < m; k++) {
      for (i = 0; i < m; i++) {
        for (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]);
        }
      }
    }
    cin >> o;
    for (i = 0; i < o; i++) {
      int p, q, r;
      cin >> p >> q >> r;
      p--;
      q--;
      if (r)
        cout << t[p][q] << endl;
      else
        cout << c[p][q] << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
void f(int c[][101], int t[][101], int a[], int p, int e, int n, int b, int v) {
  int i;
  if (p == e) {
    if (a[p] == -1 || a[p] > v)
      a[p] = v;
  } else if (a[p] == -1 || a[p] > v) {
    a[p] = v;
    for (i = 1; i < n + 1; i++) {
      if (i != p) {
        if (b) {
          if (t[p][i] != -1)
            f(c, t, a, i, e, n, b, v + t[p][i]);
        } else {
          if (c[p][i] != -1)
            f(c, t, a, i, e, n, b, v + c[p][i]);
        }
      }
    }
  }
  return;
}
int main() {
  int i;
  int c[101][101], t[101][101], a[101], m, n, o;
  int *s;
  while (cin >> m >> n && m + n) {
    memset(c, -1, sizeof(c));
    memset(t, -1, sizeof(t));
    for (i = 0; i < m; i++) {
      int p, q, r, s;
      cin >> p >> q >> r >> s;
      if (c[p][q] == -1 || c[p][q] > r) {
        c[p][q] = r;
        c[q][p] = r;
      }
      if (t[p][q] == -1 || t[p][q] > s) {
        t[p][q] = s;
        t[q][p] = s;
      }
    }
    cin >> o;
    s = new int[o];
    for (i = 0; i < o; i++) {
      int p, q, r;
      cin >> p >> q >> r;
      memset(a, -1, sizeof(a));
      f(c, t, a, p, q, n, r, 0);
      s[i] = a[q];
      cout << s[i] << endl;
    }
    delete[] s;
  }
  return 0;
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
#define _m_ 1
const int INF = 1e9;

int cost[101][101];
int tim[101][101];
int d[101];
bool used[101];
int V;

void dijkstra(int s, int o) {
  std::fill(d, d + V, INF);
  std::fill(used, used + V, false);
  d[s] = 0;
  while (_m_) {
    int v = -1;
    for (int u = 0; u < V; ++u) {
      if (!used[u] && (v == -1 || d[u] < d[v]))
        v = u;
    }
    if (v == -1)
      break;
    used[v] = true;
    if (o == 0) {
      for (int u = 0; u < V; ++u) {
        d[u] = std::min(d[u], d[v] + cost[v][u]);
      }
    } else {
      for (int u = 0; u < V; ++u) {
        d[u] = std::min(d[u], d[v] + tim[v][u]);
      }
    }
  }
}

int main() {
  int n, m;
  while (scanf("%d %d", &n, &m), n + m) {
    for (int i = 0; i < m; ++i) {
      for (int j = 0; j < m; ++j) {
        cost[i][j] = INF;
        tim[i][j] = INF;
      }
    }
    for (int i = 0; i < n; ++i) {
      int a, b, co, ti;
      scanf("%d %d %d %d", &a, &b, &co, &ti);
      a--, b--;
      cost[a][b] = co, cost[b][a] = co;
      tim[a][b] = ti, tim[b][a] = ti;
    }
    V = m;
    int k;
    scanf("%d", &k);
    for (int i = 0; i < k; ++i) {
      int p, q, r;
      scanf("%d %d %d", &p, &q, &r);
      p--, q--;
      dijkstra(p, r);
      printf("%d\\n", d[q]);
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
#define _m_ 1
const int INF = 1e9;

int cost[101][101];
int tim[101][101];
int d[101];
bool used[101];
int V;

void dijkstra(int s, int o) {
  std::fill(d, d + V, INF);
  std::fill(used, used + V, false);
  d[s] = 0;
  while (_m_) {
    int v = -1;
    for (int u = 0; u < V; ++u) {
      if (!used[u] && (v == -1 || d[u] < d[v]))
        v = u;
    }
    if (v == -1)
      break;
    used[v] = true;
    if (o == 0) {
      for (int u = 0; u < V; ++u) {
        d[u] = std::min(d[u], d[v] + cost[v][u]);
      }
    } else {
      for (int u = 0; u < V; ++u) {
        d[u] = std::min(d[u], d[v] + tim[v][u]);
      }
    }
  }
}

int main() {
  int n, m;
  while (scanf("%d %d", &n, &m), n + m) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        cost[i][j] = INF;
        tim[i][j] = INF;
      }
    }
    for (int i = 0; i < n; ++i) {
      int a, b, co, ti;
      scanf("%d %d %d %d", &a, &b, &co, &ti);
      a--, b--;
      cost[a][b] = co, cost[b][a] = co;
      tim[a][b] = ti, tim[b][a] = ti;
    }
    V = m;
    int k;
    scanf("%d", &k);
    for (int i = 0; i < k; ++i) {
      int p, q, r;
      scanf("%d %d %d", &p, &q, &r);
      p--, q--;
      dijkstra(p, r);
      printf("%d\\n", d[q]);
    }
  }
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

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

#define MAX 256
#define INF 1000000

struct edge {
  int money;
  int time;
};

int main() {
  int n, m;
  int count;
  edge G[120][120];

  while (cin >> n >> m, n || m) {
    for (int i = 0; i < 120; i++) {
      for (int j = 0; j < 120; j++) {
        G[i][j].money = INF;
        G[i][j].time = INF;
      }
    }
    for (int i = 0; i < 120; i++) {
      G[i][i].money = 0;
      G[i][i].time = 0;
    }

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

      G[a][b].time = t;
      G[a][b].money = mo;
      G[b][a].time = t;
      G[b][a].money = mo;
    }

    for (int k = 1; k <= m; k++) {
      for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= m; j++) {
          G[i][j].time = min(G[i][j].time, G[i][k].time + G[k][j].time);
          G[i][j].money = min(G[i][j].money, G[i][k].money + G[k][j].money);
        }
      }
    }

    cin >> count;
    for (int i = 0; i < count; i++) {
      int p;
      cin >> n >> m >> p;

      if (p)
        cout << G[n][m].time << endl;
      else
        cout << G[n][m].money << endl;
    }
  }
}

Error: 0

Fixed submission:

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

#define MAX 256
#define INF 1000000

struct edge {
  int money;
  int time;
};

int main() {
  int n, m;
  int count;
  edge G[120][120];

  while (cin >> n >> m, n || m) {
    for (int i = 0; i < 120; i++) {
      for (int j = 0; j < 120; j++) {
        G[i][j].money = INF;
        G[i][j].time = INF;
      }
    }
    for (int i = 0; i < 120; i++) {
      G[i][i].money = 0;
      G[i][i].time = 0;
    }

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

      G[a][b].time = t;
      G[a][b].money = mo;
      G[b][a].time = t;
      G[b][a].money = mo;
    }

    for (int k = 0; k < n; k++) {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          G[i][j].time = min(G[i][j].time, G[i][k].time + G[k][j].time);
          G[i][j].money = min(G[i][j].money, G[i][k].money + G[k][j].money);
        }
      }
    }

    cin >> count;
    for (int i = 0; i < count; i++) {
      int p;
      cin >> n >> m >> p;

      if (p)
        cout << G[n][m].time << endl;
      else
        cout << G[n][m].money << endl;
    }
  }
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

// 2013/11/15(Fri)

#include <iostream>
using namespace std;
int main() {
  int n, m;
  int a, b, cost[100][100], time[100][100];
  int k;
  int p, q, r;
  int INF = 1000001;

  while (true) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;

    for (int i = 0; i < m; i++)
      for (int j = 0; j < m; j++) {
        if (i == j) {
          cost[i][j] = 0;
          time[i][j] = 0;
        } else {
          cost[i][j] = INF;
          time[i][j] = INF;
        }
      }

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

    for (int h = 0; h < m; h++)
      for (int i = 0; i < m; i++)
        for (int j = 0; j < m; j++) {
          if (cost[i][j] > cost[i][h] + cost[h][j])
            cost[i][j] = cost[i][h] + cost[h][j];
          if (time[i][j] > time[i][h] + time[h][j])
            time[i][j] = time[i][h] + time[h][j];
        }

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

      if (r == 0)
        cout << cost[p - 1][q - 1] << endl;
      else if (r == 1)
        cout << time[p - 1][q - 1] << endl;
    }
  }
  return 0;
}

Error: -11

Fixed submission:

// 2013/11/15(Fri)

#include <iostream>
using namespace std;
int main() {
  int n, m;
  int a, b, cost[3000][3000], time[3000][3000];
  int k;
  int p, q, r;
  int INF = 1001;

  int dcost[3000][3000], dtime[3000][3000];
  while (true) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;

    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) {
        if (i == j) {
          cost[i][j] = 0;
          time[i][j] = 0;
        } else {
          cost[i][j] = INF;
          time[i][j] = INF;
        }
      }

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

    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) {
        dcost[i][j] = cost[i][j];
        dtime[i][j] = time[i][j];
      }
    for (int h = 0; h < n; h++)
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
          if (dcost[i][j] > dcost[i][h] + dcost[h][j])
            dcost[i][j] = dcost[i][h] + dcost[h][j];
          if (dtime[i][j] > dtime[i][h] + dtime[h][j])
            dtime[i][j] = dtime[i][h] + dtime[h][j];
        }

    cin >> k;
    for (int i = 0; i < k; i++) {
      cin >> p >> q >> r;
      if (r == 0)
        cout << dcost[p][q] << endl;
      else if (r == 1)
        cout << dtime[p][q] << endl;
    }
  }
  return 0;
}
Problem p00200 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;
const int INF = 1000000;
int cost[101][101], ttime[101][101];
int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    int a, b, icost, itime, c, r;
    for (int i = 0; i <= m; ++i) {
      for (int j = 0; j <= m; ++j) {
        if (i == j) {
          cost[i][i] = 0;
          ttime[i][i] = 0;
        } else {
          cost[i][j] = INF;
          ttime[i][j] = INF;
        }
      }
    }
    for (int i = 0; i < n; ++i) {
      cin >> a >> b >> icost >> itime;
      cost[a][b] = cost[b][a] = icost;
      ttime[a][b] = ttime[b][a] = itime;
    }
    for (int k = 0; k <= m; ++k) {
      for (int i = 0; i <= m; ++i) {
        for (int j = 0; j <= m; ++j) {
          ttime[i][j] = min(ttime[i][j], ttime[i][k] + ttime[k][j]);
          cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
        }
      }
    }
    cin >> c;
    for (int i = 0; i < c; ++i) {
      cin >> a >> b >> r;
      if (r == 1)
        cout << ttime[a][b] << endl;
      else
        cout << cost[a][b] << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
const int INF = 1000000;
int cost[101][101], ttime[101][101];
int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    int a, b, icost, itime, c, r;
    for (int i = 0; i <= m; ++i) {
      for (int j = 0; j <= m; ++j) {
        if (i == j) {
          cost[i][i] = 0;
          ttime[i][i] = 0;
        } else {
          cost[i][j] = INF;
          ttime[i][j] = INF;
        }
      }
    }
    for (int i = 0; i < n; ++i) {
      cin >> a >> b >> icost >> itime;
      cost[a][b] = cost[b][a] = icost;
      ttime[a][b] = ttime[b][a] = itime;
    }
    cin >> c;
    for (int d = 0; d < c; ++d) {
      cin >> a >> b >> r;
      for (int k = 0; k <= m; ++k) {
        for (int i = 0; i <= m; ++i) {
          for (int j = 0; j <= m; ++j) {
            if (r == 1)
              ttime[i][j] = min(ttime[i][j], ttime[i][k] + ttime[k][j]);
            else
              cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
          }
        }
      }
      if (r == 1)
        cout << ttime[a][b] << endl;
      else
        cout << cost[a][b] << endl;
    }
  }
  return 0;
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

const int INF = 1e9;
#define rep(i, b) for (int i = 0; i < b; i++)
#define repi(i, a, b) for (int i = a; i < b; i++)

using namespace std;

int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    int w[128][128][2];
    rep(i, m + 1) rep(j, m + 1) rep(k, 2) w[i][j][k] = INF;

    rep(i, n) {
      int a, b, c, t;
      cin >> a >> b >> c >> t;
      w[a][b][0] = c;
      w[b][a][0] = c;
      w[a][b][1] = t;
      w[b][a][1] = t;
    }
    rep(l, 2) repi(k, 1, m + 1) repi(i, 1, m + 1) repi(j, 1, m + 1) w[i][j][l] =
        min(w[i][j][l], w[i][k][l] + w[k][j][l]);

    int k;
    cin >> k;

    rep(i, k) {
      int p, q, r;
      cin >> p >> q >> r;
      cout << w[p][q][r] << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define FOR(I, F, N) for (int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout << V << endl
#define pb push_back
#define INF (1 << 30)

template <typename T> void remove(vector<T> &vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int cost[120][120];
int timm[120][120];
int n, m;

int main(void) {
  while (cin >> n >> m, n || m) {
    fill_n(*cost, 120 * 120, 10000000);
    fill_n(*timm, 120 * 120, 10000000);
    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;
      timm[a][b] = t;
      timm[b][a] = t;
    }
    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]);
          timm[i][j] = min(timm[i][j], timm[i][k] + timm[k][j]);
        }
    int k;
    cin >> k;
    rep(i, k) {
      int a, b, c;
      cin >> a >> b >> c;
      if (!c)
        cout << cost[a][b] << endl;
      else
        cout << timm[a][b] << endl;
    }
  }

  return 0;
}

int StrToInt(string s) {
  stringstream ss;
  ss << s;
  int val;
  ss >> val;
  return val;
}
string IntToStr(int i) {
  stringstream ss;
  ss << i;
  return ss.str();
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

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

constexpr int MAX_N = 100;
constexpr int INF = 100000000;

typedef std::pair<int, int> P;

struct edge {
  int to, cost;
  edge(int t, int c) : to(t), cost(c) {}
};

int n, m, K;
std::vector<edge> G[2][MAX_N];
int d[MAX_N];

void dijkstra(int s, int r) {
  std::fill(d, d + n, INF);
  d[s] = 0;
  std::priority_queue<P, std::vector<P>, std::greater<P>> que;
  que.push(P(d[s], s));

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

int main() {
  int a, b, c, t;
  while (1) {
    std::cin >> m >> n;
    if (m + n == 0)
      break;

    for (int i = 0; i < 2; ++i) {
      for (int j = 0; j < n; ++j)
        G[i][j].clear();
    }

    for (int i = 0; i < m; ++i) {
      std::cin >> a >> b >> c >> t;
      G[0][a - 1].push_back(edge(b - 1, c));
      G[0][b - 1].push_back(edge(a - 1, c));
      G[1][a - 1].push_back(edge(b - 1, t));
      G[1][b - 1].push_back(edge(a - 1, t));
    }
    std::cin >> K;
    int p, q, r;
    for (int i = 0; i < K; ++i) {
      std::cin >> p >> q >> r;
      dijkstra(p - 1, r);
      std::cout << d[q - 1] << std::endl;
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>

#define INF 1e6
#define MAX_V 100

int e, v, K;

int d[2][MAX_V][MAX_V];

int main() {
  while (1) {
    for (int i = 0; i < v; ++i) {
      for (int j = 0; j < v; ++j) {
        d[0][i][j] = (i == j) ? 0 : INF;
        d[1][i][j] = (i == j) ? 0 : INF;
      }
    }
    int a, b, cost, time;
    std::cin >> e >> v;
    if ((e + v) == 0)
      break;
    for (int i = 0; i < e; ++i) {
      std::cin >> a >> b >> cost >> time;
      d[0][a][b] = cost;
      d[0][b][a] = cost;
      d[1][a][b] = time;
      d[1][b][a] = time;
    }
    for (int k = 0; k < v; ++k) {
      for (int i = 0; i < v; ++i) {
        for (int j = 0; j < v; ++j) {
          d[0][i][j] = std::min(d[0][i][j], d[0][i][k] + d[0][k][j]);
          d[1][i][j] = std::min(d[1][i][j], d[1][i][k] + d[1][k][j]);
        }
      }
    }
    int p, q, r;
    std::cin >> K;
    for (int i = 0; i < K; ++i) {
      std::cin >> p >> q >> r;
      std::cout << d[r][p - 1][q - 1] << std::endl;
    }
  }
  return 0;
}