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

#include <stdio.h>

int main() {
  int a, b, n, step = 1;
  while (scanf("%d %d", &a, &b) != 0) {
    if (a == 0 || b == 0)
      break;
    if (a <= b) {
      n = a;
      a = b;
      b = n;
    }
    if (a % b == 0)
      n = b;
    while (a % b != 0) {
      step++;
      if (a % b == 0) {
        n = b;
        break;
      }
      a = a % b;
      n = a;
      a = b;
      b = n;
    }
    printf("%d %d\\n", n, step);
    step = 1;
  }
  return 0;
}

Error: -8

Fixed submission:

#include <stdio.h>

int main() {
  int a, b, n, step = 1;
  while (scanf("%d %d", &a, &b) != EOF) {
    if (a <= b) {
      n = a;
      a = b;
      b = n;
    }
    if (a % b == 0)
      n = b;
    while (a % b != 0) {
      step++;
      if (a % b == 0) {
        n = b;
        break;
      }
      a = a % b;
      n = a;
      a = b;
      b = n;
    }
    printf("%d %d\\n", n, step);
    step = 1;
  }
  return 0;
}
Problem p00197 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int count;

int gcd(int m, int n) {
  if (m < n) {
    int t = m;
    m = n;
    n = t;
  }
  if (n == 0)
    return m;
  count++;
  int tmp = m % n;
  return gcd(n, tmp);
}

int main() {
  int m, n;
  while (cin >> m >> n) {
    count = 0;
    if (m == 0 && n == 0)
      break;
    cout << gcd(m, n);
    cout << " " << count << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

int bin_search(int x[], int size, int key) {
  int low = 0, high = size;
  int count = 1;
  while (low < high) {
    int mid = (low + high) / 2;
    if (x[mid] == key)
      return count;
    else if (x[mid] > key)
      high = mid - 1;
    else
      low = mid + 1;
    count++;
  }
  return count;
}
int main() {
  int size;
  int key;
  int x[101];
  while (cin >> size) {
    if (size == 0)
      break;
    for (int i = 0; i < size; i++) {
      cin >> x[i];
    }
    cin >> key;
    cout << bin_search(x, size, key) << endl;
  }
  return 0;
}
Problem p00197 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>

using namespace std;

void change(int *, int *);

int main(void) {
  int x, y;

  while (1) {
    scanf("%d %d", &x, &y);
    if (x == 0 && y == 0)
      break;
    int count = 0;
    if (x < y)
      change(&x, &y);
    while (y) {
      count++;
      x %= y;
      change(&x, &y);
    }
    cout << x << ' ' << count << endl;
  }
  return 0;
}

void change(int *a, int *b) {
  int temp;
  temp = *a;
  *a = *b;
  *b = temp;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

void change(int *, int *);

int main(void) {
  int x, y;

  while (scanf("%d %d", &x, &y)) {
    int count = 0;
    if (x < y)
      change(&x, &y);
    while (y) {
      count++;
      x %= y;
      change(&x, &y);
    }
    cout << x << ' ' << count << endl;
  }
  return 0;
}

void change(int *a, int *b) {
  int temp;
  temp = *a;
  *a = *b;
  *b = temp;
}
Problem p00197 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>

int main() {
  int x = 0, y = 0;
  int temp;
  int count;
  while (scanf("%d %d", &x, &y) != EOF) {
    if (x == 0 && y == 0) {
      break;
    }

    temp = 0;

    if (x < y) {
      temp = x;
      x = y;
      y = temp;
    }

    for (count = 0; y != 0; count++) {
      x = x % y;
      temp = x;
      x = y;
      y = temp;
    }

    printf("%d %d\\n", x, count);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int N;
int Ns, Nl;
int num[4];
int S[4], L[4];
int result;

int main() {
  while (true) {
    result = 0;
    cin >> N;

    if (!N)
      break;

    if (N != 6174) {
      num[0] = N / 1000;
      N %= 1000;
      num[1] = N / 100;
      N %= 100;
      num[2] = N / 10;
      N %= 10;
      num[3] = N;

      while (true) {
        Ns = 0;
        Nl = 0;
        int judge = 0;
        for (int i = 0; i < 4; i++) {
          if (num[0] == num[i])
            judge++;
        }

        if (judge == 4) {
          cout << "NA" << endl;
          break;
        }

        sort(num, num + 4);
        for (int i = 0; i < 4; i++) {
          S[i] = num[i];
        }

        Ns += S[0] * 1000;
        Ns += S[1] * 100;
        Ns += S[2] * 10;
        Ns += S[3];

        sort(num, num + 4, greater<int>());
        for (int i = 0; i < 4; i++) {
          L[i] = num[i];
        }

        Nl += L[0] * 1000;
        Nl += L[1] * 100;
        Nl += L[2] * 10;
        Nl += L[3];

        N = Nl - Ns;

        num[0] = N / 1000;
        N %= 1000;
        num[1] = N / 100;
        N %= 100;
        num[2] = N / 10;
        N %= 10;
        num[3] = N;

        result++;

        if (num[0] == 6 && num[1] == 1 && num[2] == 7 && num[3] == 4) {
          cout << result << endl;
          break;
        }
      }
    } else
      cout << 0 << endl;
  }

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

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  while (1) {
    long long x, y, cnt = 0;
    cin >> x >> y;
    if (x + y == 0)
      break;
    if (x < y)
      swap(x, y);
    while (1) {
      cnt++;
      x %= y;
      swap(x, y);
      if (y == 0)
        break;
    }
    printf("%lld %lld\\n", x, cnt);
  }
  return 0;
}

Error: -8

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  while (1) {
    long long x, y, cnt = 0;
    cin >> x >> y;
    if (x < y)
      swap(x, y);
    while (1) {
      cnt++;
      x %= y;
      swap(x, y);
      if (y == 0)
        break;
    }
    printf("%lld %lld\\n", x, cnt);
  }
  return 0;
}
Problem p00197 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

using namespace std;

long long int yuku(long long int x, long long int y) {
  long long int t = x % y;
  x = y;
  y = t;
  if (y == 0)
    return x;
  else
    yuku(x, y);
};
long long int yu(long long int x, long long int y, long long int sum) {
  long long int t = x % y;
  x = y;
  y = t;
  sum++;
  if (y == 0)
    return sum;
  else
    yu(x, y, sum);
};

int main() {

  long long int x, y;
  while (1) {
    cin >> x >> y;
    if (x == y && x == 0)
      break;
    if (y > x)
      swap(x, y);
    long long int R = yuku(x, y);
    long long int sum = 0;
    sum = yu(x, y, sum);

    cout << R << " " << sum << endl;
  }
  return 0;
}

Error: -8

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

using namespace std;

int yuku(int x, int y) {
  int t = x % y;
  x = y;
  y = t;
  if (y == 0)
    return x;
  else
    yuku(x, y);
};
int yu(int x, int y, int sum) {
  int t = x % y;
  x = y;
  y = t;
  sum++;
  if (y == 0)
    return sum;
  else
    yu(x, y, sum);
};

int main() {

  int x, y;
  while (1) {
    cin >> x >> y;
    int R = yuku(x, y);
    int sum = 0;
    sum = yu(x, y, sum);

    cout << R << " " << sum << endl;
  }
  return 0;
}
Problem p00197 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int a, b, r, kouyaku[1001], kazu[1001], kaisuu, s;
  kaisuu = 0;
  while (1) {
    cin >> a >> b;
    if (a == 0 && b == 0) {
      break;
    }
    if (a <= b) {
      r = a;
      a = b;
      b = r;
    }
    kaisuu = kaisuu + 1;
    s = 0;
    while (b != 0) {
      s = s + 1;
      r = a % b;
      a = b;
      b = r;
    }
    kouyaku[kaisuu] = a;
    kazu[kaisuu] = s;
  }
  for (int i = 1; i <= kaisuu; i++) {
    cout << kouyaku[i] << " " << kazu[i] << endl;
  }
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a, b, r, kouyaku[1001], kazu[1001], kaisuu, s;
  kaisuu = 0;
  while (1) {
    cin >> a >> b;
    if (a == 0 && b == 0) {
      goto aa;
    }
    kaisuu = kaisuu + 1;
    s = 0;
    while (1) {
      s = s + 1;
      r = a % b;
      a = b;
      b = r;
    }
    kouyaku[kaisuu] = a;
    kazu[kaisuu] = s;
  }
aa:;
  for (int i = 1; i <= kaisuu; i++) {
    cout << kouyaku[i] << " " << kazu[i] << endl;
  }
}
Problem p00200 (C++) — buggy submission, verdict: Time Limit Exceeded

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

class S {
public:
  S(int pos, int cost) {
    p = pos;
    c = cost;
  }
  int p, c;
};
bool operator<(S a, S b) { return a.c > b.c; }
int m;
vector<S> edge[100][2];
void add_edge(int a, int b, int c, int t) {
  edge[a][0].push_back(S(b, c));
  edge[a][1].push_back(S(b, t));
  edge[b][0].push_back(S(a, c));
  edge[b][1].push_back(S(a, t));
}

int solve(int p, int q, int r) {
  int ans = 0;
  bool use[100];
  for (int i = 0; i < 100; i++) {
    use[i] = 0;
  }

  priority_queue<S> que;
  que.push(S(p, 0));

  while (!que.empty()) {
    S n = que.top();
    que.pop();

    if (n.p == q) {
      ans = n.c;
      break;
    }

    if (use[n.p]) {
      continue;
    }
    use[n.p] = 1;

    for (int i = 0; i < edge[n.p][r].size(); i++) {
      if (!use[edge[n.p][r][i].p]) {
        que.push(S(edge[n.p][r][i].p, n.c + edge[n.p][r][i].c));
      }
    }
  }
  return ans;
}

int main() {
  int n;
  while (cin >> n >> m, n != 0 || m != 0) {
    for (int i = 0; i < 100; i++) {
      for (int j = 0; j < 2; j++) {
        edge[i][j].clear();
      }
    }
    for (int i = 0; i < n; i++) {
      int a, b, c, t;
      cin >> a >> b >> c >> t;
      a--;
      b--;
      add_edge(a, b, c, t);
    }
    int k;
    cin >> k;
    for (int i = 0; i < k; i++) {
      int p, q, r;
      cin >> p >> q >> r;
      p--;
      q--;
      cout << solve(p, q, r) << endl;
    }
  }
}

Error: TLE

Fixed submission:

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

class S {
public:
  S(int pos, int cost) {
    p = pos;
    c = cost;
  }
  int p, c;
};
bool operator<(S a, S b) { return a.c > b.c; }
int m;
vector<S> edge[100][2];
void add_edge(int a, int b, int c, int t) {
  edge[a][0].push_back(S(b, c));
  edge[a][1].push_back(S(b, t));
  edge[b][0].push_back(S(a, c));
  edge[b][1].push_back(S(a, t));
}

int solve(int p, int q, int r) {
  int ans = 0;
  bool use[100];
  for (int i = 0; i < 100; i++) {
    use[i] = 0;
  }

  priority_queue<S> que;
  que.push(S(p, 0));

  while (!que.empty()) {
    S n = que.top();
    que.pop();

    if (n.p == q) {
      ans = n.c;
      break;
    }

    if (use[n.p]) {
      continue;
    }
    use[n.p] = 1;

    for (int i = 0; i < edge[n.p][r].size(); i++) {
      if (!use[edge[n.p][r][i].p]) {
        que.push(S(edge[n.p][r][i].p, n.c + edge[n.p][r][i].c));
      }
    }
  }
  return ans;
}

int main() {
  int n;
  while (cin >> n >> m, n != 0 || m != 0) {
    for (int i = 0; i < n; i++) {
      int a, b, c, t;
      cin >> a >> b >> c >> t;
      a--;
      b--;
      add_edge(a, b, c, t);
    }
    int k;
    cin >> k;
    for (int i = 0; i < k; i++) {
      int p, q, r;
      cin >> p >> q >> r;
      p--;
      q--;
      cout << solve(p, q, r) << endl;
    }
  }
}
Problem p00200 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
#define INF (int)1e9

void warshall_floyd(int m, int p, int q, std::vector<std::vector<int>> &dp) {
  for (int i = 0; i < m; i++) {
    dp[i][i] = 0;
  }
  for (int k = 0; k < m; k++) {
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        dp[i][j] = std::min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }
  return;
}

int main(void) {
  int n;
  int m;
  int a;
  int b;
  int cost;
  int time;
  int k;
  int p;
  int q;
  int r;

  while (true) {
    std::cin >> n >> m;
    if (n == 0 && m == 0) {
      break;
    }
    std::vector<std::vector<int>> vcost(m, std::vector<int>(m, INF));
    std::vector<std::vector<int>> vtime(m, std::vector<int>(m, INF));

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

    warshall_floyd(m, p, q, vcost);
    warshall_floyd(m, p, q, vtime);
    std::cin >> k;
    for (int i = 0; i < k; i++) {
      std::cin >> p >> q >> r;
      --p;
      --q;
      if (r == 0) {
        std::cout << vcost[p][q] << std::endl;
      } else {
        std::cout << vtime[p][q] << std::endl;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
#define INF (int)1e9

void warshall_floyd(int m, int p, int q, std::vector<std::vector<int>> dp) {
  for (int i = 0; i < m; i++) {
    dp[i][i] = 0;
  }
  for (int k = 0; k < m; k++) {
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        dp[i][j] = std::min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }
  std::cout << dp[p][q] << std::endl;
  return;
}

int main(void) {
  int n;
  int m;
  int a;
  int b;
  int cost;
  int time;
  int k;
  int p;
  int q;
  int r;

  while (true) {
    std::cin >> n >> m;
    if (n == 0 && m == 0) {
      break;
    }
    std::vector<std::vector<int>> vcost(m, std::vector<int>(m, INF));
    std::vector<std::vector<int>> vtime(m, std::vector<int>(m, INF));

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

    std::cin >> k;
    for (int i = 0; i < k; i++) {
      std::cin >> p >> q >> r;
      --p;
      --q;
      if (r == 0) {
        warshall_floyd(m, p, q, vcost);
      } else {
        warshall_floyd(m, p, q, vtime);
      }
    }
  }
  return 0;
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <string>
#define INF (1 << 21)
using namespace std;

int main() {
  int i, j, k, kk, aa, bb, n, m, a, b, d, dd, c[101][101], t[101][101], f;
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;

    for (i = 1; i <= m; i++) {
      for (j = 1; j <= m; j++) {
        if (i == j) {
          c[i][j] = 0;
          t[i][j] = 0;
        } else {
          c[i][j] = INF;
          t[i][j] = INF;
        }
      }
    }

    for (i = 0; i < n; i++) {
      cin >> a >> b >> d >> dd;
      c[a][b] = c[b][a] = d;
      t[a][b] = t[b][a] = dd;
    }

    for (k = 1; k <= m; k++) {
      for (i = 1; i <= m; i++) {
        for (j = 1; j <= m; j++) {
          if (t[i][k] >= INF || t[k][j] >= INF || c[i][k] >= INF ||
              c[k][j] >= INF)
            continue;
          if (t[i][k] + t[k][j] > INF || c[i][k] + c[k][j] > INF)
            continue;
          t[i][j] = min(t[i][j], t[i][k] + t[k][j]);
          c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
        }
      }
    }

    cin >> kk;
    for (i = 0; i < kk; i++) {
      cin >> aa >> bb >> f;
      if (f)
        cout << t[aa][bb] << endl;
      else
        cout << c[aa][bb] << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>
#define INF (1 << 21)
using namespace std;

int main() {
  int i, j, k, n, m, a, b, d, dd, c[300][300], t[300][300];
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;

    for (i = 0; i <= n; i++) {
      for (j = 0; j <= n; j++) {
        c[i][j] = INF;
        t[i][j] = INF;
        if (i == j) {
          c[i][j] = 0;
          t[i][j] = 0;
        }
      }
    }

    for (i = 0; i < n; i++) {
      cin >> a >> b >> d >> dd;
      c[a][b] = c[b][a] = d;
      t[a][b] = t[b][a] = dd;
    }

    for (i = 0; i <= m; i++) {
      for (j = 0; j <= m; j++) {
        for (k = 0; k <= m; k++) {
          if (t[i][j] > t[i][k] + t[k][j])
            t[i][j] = t[i][k] + t[k][j];
          if (c[i][j] > c[i][k] + c[k][j])
            c[i][j] = c[i][k] + c[k][j];
        }
      }
    }

    cin >> k;
    for (i = 0; i < k; i++) {
      cin >> a >> b >> d;
      if (d)
        cout << t[a][b] << endl;
      else
        cout << c[a][b] << endl;
    }
  }
  return 0;
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define INF 1e9
using namespace std;
typedef long long ll;

ll min(ll a, ll b) {
  if (a > b)
    return b;
  else
    return a;
}

int main() {
  int n, m, a, b, cost, time, l, p, q, r;
  while (cin >> n >> m, n || m) {
    ll mt[m][m], mc[m][m];
    rep(i, m) rep(j, m) mt[i][j] = mc[i][j] = INF;
    rep(i, n) {
      cin >> a >> b >> cost >> time;
      mt[a - 1][b - 1] = mt[b - 1][a - 1] = time;
      mc[a - 1][b - 1] = mc[b - 1][a - 1] = cost;
    }
    rep(k, m) {
      rep(i, m) {
        rep(j, m) {
          mt[i][j] = min(mt[i][j], mt[i][k] + mt[k][j]);
          mc[i][j] = min(mc[i][j], mc[i][k] + mc[k][j]);
        }
      }
    }
    cin >> l;
    rep(i, l) {
      cin >> p >> q >> r;
      if (r == 0)
        cout << mc[p - 1][q - 1] << endl;
      else
        cout << mt[p - 1][q - 1] << endl;
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <cmath>
#include <iostream>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define INF 1e6
using namespace std;

int main() {
  int n, m, a, b, cost, time, l, p, q, r;
  while (cin >> n >> m, n || m) {
    int mt[m][m], mc[m][m];
    rep(i, m) rep(j, m) mt[i][j] = mc[i][j] = INF;
    rep(i, n) {
      cin >> a >> b >> cost >> time;
      mt[a - 1][b - 1] = mt[b - 1][a - 1] = time;
      mc[a - 1][b - 1] = mt[b - 1][a - 1] = cost;
    }
    rep(k, n) {
      rep(i, n) {
        rep(j, n) {
          mt[i][j] = min(mt[i][j], mt[i][k] + mt[k][j]);
          mc[i][j] = min(mc[i][j], mc[i][k] + mc[k][j]);
        }
      }
    }
    cin >> l;
    rep(i, l) {
      cin >> p >> q >> r;
      if (r == 0)
        cout << mc[p - 1][q - 1] << endl;
      else
        cout << mt[p - 1][q - 1] << endl;
    }
  }
  return 0;
}
Problem p00200 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)
#define all(n) n.begin(), n.end()

const int MAXN = 3000, MAXM = 100, C = 0, T = 1;
const int INF = 1 << 28;
int cost[2][MAXM + 10][MAXM + 10];

int main() {
  int n, m;
  while (cin >> n >> m && n) {
    int a, b, cc, ct;
    REP(MAXM) rep(j, MAXM) rep(e, 2) cost[e][i][j] = INF;
    REP(n) {
      cin >> a >> b >> cc >> ct;
      a--;
      b--;
      cost[C][a][b] = cost[C][b][a] = min(cc, cost[C][a][b]);
      cost[T][a][b] = cost[T][b][a] = min(ct, cost[T][a][b]);
    }

    int k, p, q, r;
    cin >> k;
    int d[MAXM] = {}, used[MAXM] = {};
    rep(s, k) {
      cin >> p >> q >> r;
      p--;
      q--;
      memset(used, 0, sizeof(used));
      REP(m) d[i] = INF;
      d[p] = 0;
      while (true) {
        int v = -1;
        rep(i, m) if (!used[i] && (v == -1 || d[i] < d[v])) v = i;
        if (v == -1)
          break;
        used[v] = true;
        rep(i, m) d[i] = min(d[i], d[v] + cost[r][v][i]);
      }
      cout << d[q] << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

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

const int INF = 1 << 28, MAXM = 101, COST = 0, TIME = 1;

int cost[2][MAXM][MAXM];

int main() {
  int n, m, a, b, c, t;
  while (cin >> n >> m) {
    REP(2) rep(j, m) rep(k, m) cost[i][j][k] = INF;
    // fill(cost, sizeof(cost), INF);
    REP(n) {
      cin >> a >> b >> c >> t;
      a--;
      b--;
      cost[TIME][a][b] = cost[TIME][b][a] = t;
      cost[COST][a][b] = cost[COST][b][a] = c;
    }

    int k;
    cin >> k;
    int p, q, r;
    rep(s, k) {
      cin >> p >> q >> r;
      p--;
      q--;

      // rep(i,m)rep(j,m) d[i][j] = cost[r][i][j];

      rep(l, m) rep(i, m) rep(j, m) {
        cost[TIME][i][j] =
            min(cost[TIME][i][j], cost[TIME][i][l] + cost[TIME][l][j]);
        cost[COST][i][j] =
            min(cost[COST][i][j], cost[COST][i][l] + cost[COST][l][j]);
      }
      cout << cost[r][p][q] << endl;
    }
  }
  return 0;
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
using namespace std;

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

const int maxn = 311, maxm = 110, INF = 110000;
const int COST = 0, TIME = 1;

int n, m;

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

typedef pair<int, int> p;

int main() {
  while (cin >> n >> m && (n || m)) {
    vector<edge> cost[2][maxn];
    int a, b, tc, tt;
    REP(n) {
      cin >> a >> b >> tc >> tt;
      cost[TIME][a].push_back(edge(b, tt));
      cost[TIME][b].push_back(edge(a, tt));
      cost[COST][a].push_back(edge(b, tc));
      cost[COST][b].push_back(edge(a, tc));
    }

    int k;
    cin >> k;

    int start, goll, r;
    while (k--) {
      cin >> start >> goll >> r;
      int d[maxm] = {};
      memset(d, INF, sizeof(d));
      d[start] = 0;

      priority_queue<p, vector<p>, greater<p>> que;
      que.push(p(0, start));

      while (!que.empty()) {
        p tp = que.top();
        que.pop();
        int v = tp.second; // 確定ノード
        // cout << v << endl;
        if (d[v] < tp.first)
          continue;
        REP(cost[r][v].size()) {
          edge e = cost[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));
          }
        }
      }
      cout << d[goll] << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define INF 30000

struct E {
  int a, b, c, t;
  E(){};
  E(int a, int b, int c, int t) : a(a), b(b), c(c), t(t){};
};
E cs[1000];
unsigned int d[310];

int main() {
  int n, m, k, p, q, r;
  while (cin >> n >> m) {
    if (n == 0 && m == 0)
      break;

    int ta, tb, tc, tt;
    for (int i = 0; i < 2 * n; i += 2) {
      cin >> ta >> tb >> tc >> tt;
      cs[i].a = ta;
      cs[i].b = tb;
      cs[i].c = tc;
      cs[i].t = tt;
      cs[i + 1].a = tb;
      cs[i + 1].b = ta;
      cs[i + 1].c = tc;
      cs[i + 1].t = tt;
      // cs[i] = E(ta,tb,tc,tt);
      // cs[i+1] = E(tb,ta,tc,tt);
    }

    cin >> k;
    rep(i, k) {
      memset(d, INF, sizeof(d));
      cin >> p >> q >> r;
      d[p] = 0;

      int update = 0;
      if (r == 0)
        while (true) {
          update = 0;
          rep(j, n * 2) {
            if (d[cs[j].a] != INF && d[cs[j].b] > d[cs[j].a] + cs[j].c) {
              update = 1;
              d[cs[j].b] = d[cs[j].a] + cs[j].c;
            }
          }
          if (!update)
            break;
        }
      if (r == 1)
        while (true) {
          update = 0;
          rep(j, n * 2) {
            if (d[cs[j].a] != INF && d[cs[j].b] > d[cs[j].a] + cs[j].t) {
              update = 1;
              d[cs[j].b] = d[cs[j].a] + cs[j].t;
            }
          }
          if (!update)
            break;
        }
      cout << d[q] << endl;
    }
  }

  return 0;
}