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

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

constexpr int INF = 1000000000;

using Pair = std::pair<int, int>;

int n, m;
std::vector<Pair> cost[101];
std::vector<Pair> time_[101];

int d[101];
int dijkstra(int st, int gl, std::vector<Pair> *elm) {
  std::fill(d, d + 101, INF);

  d[st] = 0;

  std::priority_queue<Pair, std::vector<Pair>, std::greater<Pair>> queue;

  queue.push({0, st});

  while (!queue.empty()) {
    auto p = queue.top();
    queue.pop();

    if (p.first > d[p.second]) {
      continue;
    }

    for (int i = 0; i < elm[p.second].size(); ++i) {
      auto e = elm[p.second][i];

      // To, cost

      if (d[e.first] > d[p.second] + e.second) {
        d[e.first] = d[p.second] + e.second;

        queue.push({d[e.first], e.first});
      }
    }
  }

  return d[gl];
}

int main() {
  while (std::cin >> n >> m, n + m) {
    int a, b, c, t;

    for (int i = 0; i < m; ++i) {
      cost[i].clear();
      time_[i].clear();
    }

    for (int i = 0; i < n; ++i) {
      std::cin >> a >> b >> c >> t;

      --a, --b;

      cost[a].push_back({b, c});
      cost[b].push_back({a, c});
      time_[a].push_back({b, t});
      time_[b].push_back({a, t});
    }

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

      std::cin >> p >> q >> r;

      if (r == 0) {
        std::cout << dijkstra(p - 1, q - 1, cost) << std::endl;
      } else {
        std::cout << dijkstra(p - 1, q - 1, time_) << std::endl;
      }
    }
  }
}

Error: 0

Fixed submission:

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

constexpr int INF = 1000000000;

using Pair = std::pair<int, int>;

int n, m;
std::vector<Pair> cost[101];
std::vector<Pair> time_[101];

int d[101];
int dijkstra(int st, int gl, std::vector<Pair> *elm) {
  std::fill(d, d + 101, INF);

  d[st] = 0;

  std::priority_queue<Pair, std::vector<Pair>, std::greater<Pair>> queue;

  queue.push({0, st});

  while (!queue.empty()) {
    auto p = queue.top();
    queue.pop();

    if (p.first > d[p.second]) {
      continue;
    }

    for (int i = 0; i < elm[p.second].size(); ++i) {
      auto e = elm[p.second][i];

      // To, cost

      if (d[e.first] > d[p.second] + e.second) {
        d[e.first] = d[p.second] + e.second;

        queue.push({d[e.first], e.first});
      }
    }
  }

  return d[gl];
}

int main() {
  while (std::cin >> n >> m, n + m) {
    int a, b, c, t;

    for (int i = 0; i < n; ++i) {
      cost[i].clear();
      time_[i].clear();
    }

    for (int i = 0; i < n; ++i) {
      std::cin >> a >> b >> c >> t;

      --a, --b;

      cost[a].push_back({b, c});
      cost[b].push_back({a, c});
      time_[a].push_back({b, t});
      time_[b].push_back({a, t});
    }

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

      std::cin >> p >> q >> r;

      if (r == 0) {
        std::cout << dijkstra(p - 1, q - 1, cost) << std::endl;
      } else {
        std::cout << dijkstra(p - 1, q - 1, time_) << std::endl;
      }
    }
  }
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
int n, m;
const int MAXN = 101;
int t[MAXN][MAXN];
int c[MAXN][MAXN];

void solve() {
  for (int k = 0; k < m; ++k) {
    for (int i = 0; i < m; ++i) {
      for (int j = 0; j < m; ++j) {
        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]);
      }
    }
  }
}
const int INF = INT_MAX / 3;
void init() {
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < m; j++) {
      c[i][j] = t[i][j] = INF;
    }
  }
  for (int i = 0; i < m; i++) {
    c[i][i] = t[i][i] = 0;
  }
}

int main() {
  ios::sync_with_stdio(false);

  while (cin >> n >> m && n + m > 0) {
    init();
    int a, b, icost, itime;
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> icost >> itime;
      a--, b--;
      t[a][b] = t[b][a] = itime;
      c[a][b] = c[b][a] = icost;
    }
    solve();
    int k;
    cin >> k;
    for (int i = 0; i < k; ++i) {
      int p, q, r;
      cin >> p >> q >> r;
      p--, q--;
      if (r == 1) {
        cout << t[p][q] << endl;
      } else {
        cout << c[p][q] << endl;
      }
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
int n, m;
const int MAXN = 101;
int t[MAXN][MAXN];
int c[MAXN][MAXN];

void solve() {
  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        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]);
      }
    }
  }
}
const int INF = INT_MAX / 3;
void init() {
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; j++) {
      c[i][j] = t[i][j] = INF;
    }
  }
  for (int i = 0; i < n; i++) {
    c[i][i] = t[i][i] = 0;
  }
}

int main() {
  ios::sync_with_stdio(false);

  while (cin >> n >> m && n + m > 0) {
    init();
    int a, b, icost, itime;
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> icost >> itime;
      t[a][b] = t[b][a] = itime;
      c[a][b] = c[b][a] = icost;
    }
    solve();
    int k;
    cin >> k;
    for (int i = 0; i < k; ++i) {
      int p, q, r;
      cin >> p >> q >> r;
      if (r == 1) {
        cout << t[p][q] << endl;
      } else {
        cout << c[p][q] << endl;
      }
    }
  }
  return 0;
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <utility>

using namespace std;

int n, m;

long long gc[110][110];
long long gt[110][110];

void warshallfloyd() {
  for (int k = 0; k < m; k++) {
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        gc[i][j] = min(gc[i][j], gc[i][k] + gc[k][j]);
        gt[i][j] = min(gt[i][j], gt[i][k] + gt[k][j]);
      }
    }
  }
}

int main(void) {
  while (cin >> n >> m, n || m) {

    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        gc[i][j] = 9999999;
        gt[i][j] = 9999999;
      }
    }

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

      cin >> a >> b >> c >> t;

      a--;
      b--;

      gc[a][b] = gc[b][a] = c;
      gt[a][b] = gt[b][a] = t;
    }

    warshallfloyd();

    int k;

    cin >> k;

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

      cin >> p >> q >> r;

      p--;
      q--;

      if (r == 0) {
        cout << gc[p][q] << endl;
      } else {
        cout << gt[p][q] << endl;
      }
    }
  }

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <utility>

using namespace std;

int n, m;

long long gc[110][110];
long long gt[110][110];

void warshallfloyd() {
  for (int k = 0; k < m; k++) {
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        gc[i][j] = min(gc[i][j], gc[i][k] + gc[k][j]);
        gt[i][j] = min(gt[i][j], gt[i][k] + gt[k][j]);
      }
    }
  }
}

int main(void) {
  while (cin >> n >> m, n || m) {

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        gc[i][j] = 9999999;
        gt[i][j] = 9999999;
      }
    }

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

      cin >> a >> b >> c >> t;

      a--;
      b--;

      gc[a][b] = gc[b][a] = c;
      gt[a][b] = gt[b][a] = t;
    }

    warshallfloyd();

    int k;

    cin >> k;

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

      cin >> p >> q >> r;

      p--;
      q--;

      if (r == 0) {
        cout << gc[p][q] << endl;
      } else {
        cout << gt[p][q] << endl;
      }
    }
  }

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

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

class State {
public:
  int v, c;
  State(int _v, int _c) : v(_v), c(_c) {}

  bool operator<(const State &st) const { return this->c > st.c; }
};

int main() {
  int n, m, k;
  const int INF = 1 << 30;

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

    vector<vector<vector<int>>> score(
        2, vector<vector<int>>(m, vector<int>(m, 0)));
    int a, b, cost, time;

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

    int p, q, r;

    cin >> k;
    while (k--) {
      cin >> p >> q >> r;
      vector<int> d(m, INF);
      --q;
      --p;
      priority_queue<State> req;
      req.push(State(p, 0));
      d[p] = 0;
      while (!req.empty()) {
        State st = req.top();
        req.pop();

        if (st.v == q) {
          cout << st.c << endl;
          break;
        }

        if (d[st.v] < st.c)
          continue;

        for (int i = 0; i < m; i++) {
          if (score[r][st.v][i] != 0) {
            if (st.c + score[r][st.v][i] < d[i]) {
              d[i] = st.c + score[r][st.v][i];
              req.push(State(i, d[i]));
            }
          }
        }
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, m, k;
  const int INF = 1 << 30;

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

    vector<vector<vector<int>>> score(
        2, vector<vector<int>>(m, vector<int>(m, 0)));
    int a, b, cost, time;

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

    int p, q, r;

    cin >> k;
    while (k--) {
      cin >> p >> q >> r;
      vector<int> d(m, INF);
      --q;
      --p;
      queue<int> req;
      req.push(p);
      d[p] = 0;
      while (!req.empty()) {
        int v = req.front();
        req.pop();

        for (int i = 0; i < m; i++) {
          if (score[r][v][i] != 0) {
            if (d[v] + score[r][v][i] < d[i]) {
              d[i] = d[v] + score[r][v][i];
              req.push(i);
            }
          }
        }
      }
      cout << d[q] << endl;
    }
  }
  return 0;
}
Problem p00200 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int cost[100][100];

int main() {
  for (;;) {
    int t, tt, ttt, tttt;
    int time[100][100];

    // n:f[^Ì m:wÌ
    int n, m;

    // k:â¢í¹Ì
    int k;

    cin >> n >> m;

    if (n == 0 && m == 0) {
      break;
    }

    for (int i = 0; i < 100; i++) {
      for (int j = 0; j < 100; j++) {
        if (i != j) {
          time[i][j] = 10000000;
          cost[i][j] = 10000000;
        } else {
          cost[i][j] = time[i][j] = 0;
        }
      }
    }

    for (int i = 0; i < n; i++) {
      cin >> t >> tt >> ttt >> tttt;
      t--;
      tt--;
      cost[t][tt] = ttt;
      time[t][tt] = tttt;
      cost[tt][t] = ttt;
      time[tt][t] = tttt;
    }

    cin >> k;

    for (int f = 0; f < m; f++) {
      for (int fd = 0; fd < m; fd++) {
        for (int fds = 0; fds < m; fds++) {
          cost[fd][fds] = min(cost[fd][fds], cost[fd][f] + cost[f][fds]);
          time[fd][fds] = min(time[fd][fds], time[fd][f] + time[f][fds]);
        }
      }
    }

    for (int i = 0; i < k; i++) {
      cin >> t >> tt >> ttt;

      if (ttt == 0) {
        cout << cost[t - 1][tt - 1] << endl;
      } else {
        cout << time[t - 1][tt - 1] << endl;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int cost[100][100];

int main() {
  for (;;) {
    int t, tt, ttt, tttt;
    int time[100][100];

    // n:f[^Ì m:wÌ
    int n, m;

    // k:â¢í¹Ì
    int k;

    cin >> n >> m;

    if (n == 0 && m == 0) {
      break;
    }

    for (int i = 0; i < 100; i++) {
      for (int j = 0; j < 100; j++) {
        if (i != j) {
          time[i][j] = 10000000;
          cost[i][j] = 10000000;
        } else {
          cost[i][j] = time[i][j] = 0;
        }
      }
    }

    for (int i = 0; i < n; i++) {
      cin >> t >> tt >> ttt >> tttt;
      t--;
      tt--;
      cost[t][tt] = ttt;
      time[t][tt] = tttt;
      cost[tt][t] = ttt;
      time[tt][t] = tttt;
    }

    cin >> k;

    for (int i = 0; i < k; i++) {
      cin >> t >> tt >> ttt;

      for (int f = 0; f < m; f++) {
        for (int fd = 0; fd < m; fd++) {
          for (int fds = 0; fds < m; fds++) {
            if (ttt == 0) {
              cost[fd][fds] = min(cost[fd][fds], cost[fd][f] + cost[f][fds]);
            } else {
              time[fd][fds] = min(time[fd][fds], time[fd][f] + time[f][fds]);
            }
          }
        }
      }
      if (ttt == 0) {
        cout << cost[t - 1][tt - 1] << endl;
      } else {
        cout << time[t - 1][tt - 1] << endl;
      }
    }
  }
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

// 青春の片道切符：：ワーシャルフロイド法

/*for(int k=0;k<N;k++){//経由箇所(N<200)
        for(int i=0;i<N;i++){//スタート(N<200)
                for(int j=0;j<N;j++){//目的(N<200)
                        d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
                }
        }
}*/

#include <algorithm>
#include <cctype>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
using namespace std;

long long gc[110][110];
long long gt[110][110];
int n, m;

void warshallfroid() {
  for (int k = 0; k < m; k++) {     // 経由箇所(N<200)
    for (int i = 0; i < m; i++) {   // スタート(N<200)
      for (int j = 0; j < m; j++) { // 目的(N<200)
        gc[i][j] = min(gc[i][j], gc[i][k] + gc[k][j]);
        gt[i][j] = min(gt[i][j], gt[i][k] + gt[k][j]);
      }
    }
  }
}

int main() {

  while (cin >> n >> m, n || m /*n,mが両方0のときお終わり*/) {
    for (int i = 0; i < m; i++) {   // スタート(N<200)
      for (int j = 0; j < m; j++) { // 目的(N<200)
        gc[i][j] = 9999999;         // 初期化
        gt[i][j] = 9999999;         // 初期化
      }
    }

    for (int i = 0; i < n; i++) {
      int a, b, c, t;
      cin >> a >> b >> c >> t;
      a--, b--;
      gc[a][b] = gc[b][a] = c;
      gt[a][b] = gt[b][a] = t;
    }
    warshallfroid();

    int k;
    cin >> k;
    for (int i = 0; i < k; i++) {
      int p, q, r;
      cin >> p >> q >> r;
      p--, q--;
      if (r == 0)
        cout << gc[p][q] << endl;
      else
        cout << gt[p][q] << endl;
    }
  }
}


Error: 0

Fixed submission:

// 青春の片道切符：：ワーシャルフロイド法

/*for(int k=0;k<N;k++){//経由箇所(N<200)
        for(int i=0;i<N;i++){//スタート(N<200)
                for(int j=0;j<N;j++){//目的(N<200)
                        d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
                }
        }
}*/

#include <algorithm>
#include <cctype>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
using namespace std;

long long gc[110][110];
long long gt[110][110];
int n, m;

void warshallfroid() {
  for (int k = 0; k < m; k++) {     // 経由箇所(N<200)
    for (int i = 0; i < m; i++) {   // スタート(N<200)
      for (int j = 0; j < n; j++) { // 目的(N<200)
        gc[i][j] = min(gc[i][j], gc[i][k] + gc[k][j]);
        gt[i][j] = min(gt[i][j], gt[i][k] + gt[k][j]);
      }
    }
  }
}

int main() {

  while (cin >> n >> m, n || m /*n,mが両方0のときお終わり*/) {
    for (int i = 0; i < m; i++) {   // スタート(N<200)
      for (int j = 0; j < m; j++) { // 目的(N<200)
        gc[i][j] = 9999999;         // 初期化
        gt[i][j] = 9999999;         // 初期化
      }
    }

    for (int i = 0; i < n; i++) {
      int a, b, c, t;
      cin >> a >> b >> c >> t;
      a--, b--;
      gc[a][b] = gc[b][a] = c;
      gt[a][b] = gt[b][a] = t;
    }
    warshallfroid();

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

#include <algorithm>
#include <iostream>

using namespace std;

int main(int argc, char **argv) {
  int c[101][101], t[101][101], n, m, a, b, u, v;

  while (1) {
    cin >> n >> m;

    if (n == 0 && m == 0) {
      break;
    }

    fill(&c[1][1], &c[m][m], 99999);
    fill(&t[1][1], &t[m][m], 99999);

    for (int i = 1; i <= m; i++) {
      c[i][i] = t[i][i] = 0;
    }

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

    for (int k = 1; k <= m; k++) {
      for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= m; j++) {
          c[i][j] = (c[i][j] < c[i][k] + c[k][j]) ? c[i][j] : c[i][k] + c[k][j];
          t[i][j] = (t[i][j] < t[i][k] + t[k][j]) ? t[i][j] : t[i][k] + t[k][j];
        }
      }
    }
    cin >> n;
    while (n--) {
      cin >> a >> b >> u;
      if (u == 0) {
        cout << c[a][b] << endl;
      } else {
        cout << t[a][b] << endl;
      }
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int main(int argc, char **argv) {
  int c[100][100], t[100][100], n, m, a, b, u, v;

  while (1) {
    cin >> n >> m;

    if (n == 0 && m == 0) {
      break;
    }

    fill(&c[1][1], &c[m][m], 999);
    fill(&t[1][1], &t[m][m], 999);

    for (int i = 1; i <= m; i++) {
      c[i][i] = t[i][i] = 0;
    }

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

    for (int k = 1; k <= m; k++) {
      for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= m; j++) {
          c[i][j] = (c[i][j] < c[i][k] + c[k][j]) ? c[i][j] : c[i][k] + c[k][j];
          t[i][j] = (t[i][j] < t[i][k] + t[k][j]) ? t[i][j] : t[i][k] + t[k][j];
        }
      }
    }
    cin >> n;
    while (n--) {
      cin >> a >> b >> u;
      if (u == 0) {
        cout << c[a][b] << endl;
      } else {
        cout << t[a][b] << endl;
      }
    }
  }

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

// 2014/06/16 Tazoe

#include <iostream>
using namespace std;

const int INF = 1000000000;

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

    if (n == 0 && m == 0)
      break;

    int C[100][100];
    int T[100][100];
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        if (i == j) {
          C[i][j] = T[i][j] = 0;
        } else {
          C[i][j] = T[i][j] = INF;
        }
      }
    }

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

      C[a - 1][b - 1] = C[b - 1][a - 1] = c;
      T[a - 1][b - 1] = T[b - 1][a - 1] = t;
    }
    for (int k = 0; k < m; k++) {
      for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++) {
          if (C[i][j] > C[i][k] + C[k][j])
            C[i][j] = C[i][k] + C[k][j];
          if (T[i][j] > T[i][k] + T[k][j])
            T[i][j] = T[i][k] + T[k][j];
        }
      }
    }
    unsigned int k;
    cin >> k;
    for (int i = 0; i < k; i++) {
      int p, q, r;
      cin >> p >> q;

      cin >> r;

      if (r == 0) {
        cout << C[p - 1][q - 1] << endl;
      } else {
        cout << T[p - 1][q - 1] << endl;
      }
    }
  }

  return 0;
}


Error: WA

Fixed submission:

// 2014/06/16 Tazoe

#include <iostream>
using namespace std;

const int INF = 1000000000;

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

    if (n == 0 && m == 0)
      break;

    int C[100][100];
    int T[100][100];
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        if (i == j) {
          C[i][j] = T[i][j] = 0;
        } else {
          C[i][j] = T[i][j] = INF;
        }
      }
    }

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

      C[a - 1][b - 1] = C[b - 1][a - 1] = c;
      T[a - 1][b - 1] = T[b - 1][a - 1] = t;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        for (int k = 0; k < n; k++) {
          if (C[i][j] > C[i][k] + C[k][j])
            C[i][j] = C[i][k] + C[k][j];
          if (T[i][j] > T[i][k] + T[k][j])
            T[i][j] = T[i][k] + T[k][j];
        }
      }
    }
    unsigned int k;
    cin >> k;
    for (int i = 0; i < k; i++) {
      int p, q, r;
      cin >> p >> q;
      if (k == 0 && q == 0)
        return 0;
      cin >> r;

      if (r == 0) {
        cout << C[p][q] << endl;
      } else {
        cout << T[p][q] << endl;
      }
    }
  }

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

#include <iostream>
using namespace std;

const int INF = 1000000000;

int main() {
  while (true) {
    int n, m; // 線路の情報の数n, 駅の数m
    cin >> n >> m;

    if (n == 0 && m == 0)
      break;

    int C[100][100]; // costのグラフ
    int T[100][100]; // timeのグラフ
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        if (i == j) {
          C[i][j] = T[i][j] = 0; // 対角線は0
        } else {
          C[i][j] = T[i][j] = INF;
        }
      }
    }

    for (int i = 0; i < n; i++) {
      int a, b, c, t; // 線路の情報a,bとcost,time
      cin >> a >> b >> c >> t;

      C[a - 1][b - 1] = C[b - 1][a - 1] = c;
      T[a - 1][b - 1] = T[b - 1][a - 1] = t;
    }

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

    int k; // 問い合わせの数
    cin >> k;
    for (int i = 0; i < k; i++) {
      int p, q, r; // 出発駅p, 到着駅q, 値の種類r
      cin >> p >> q >> r;
      if (r) // r==1なら最短時間
        cout << T[p - 1][q - 1] << endl;
      else
        cout << C[p - 1][q - 1] << endl;
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

const int INF = 1000000000;

int main() {
  while (true) {
    int n, m; // 線路の情報の数n, 駅の数m
    cin >> n >> m;

    if (n == 0 && m == 0)
      break;

    int C[100][100]; // costのグラフ
    int T[100][100]; // timeのグラフ
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        if (i == j) {
          C[i][j] = T[i][j] = 0; // 対角線は0
        } else {
          C[i][j] = T[i][j] = INF;
        }
      }
    }

    for (int i = 0; i < n; i++) {
      int a, b, c, t; // 線路の情報a,bとcost,time
      cin >> a >> b >> c >> t;

      C[a - 1][b - 1] = C[b - 1][a - 1] = c;
      T[a - 1][b - 1] = T[b - 1][a - 1] = t;
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        for (int k = 0; k < n; k++) {
          if (C[j][k] > C[j][i] + C[i][k])
            C[j][k] = C[j][i] + C[i][k];
        }
      }
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        for (int k = 0; k < n; k++) {
          if (T[j][k] > T[j][i] + T[i][k])
            T[j][k] = T[j][i] + T[i][k];
        }
      }
    }

    int k; // 問い合わせの数
    cin >> k;
    for (int i = 0; i < k; i++) {
      int p, q, r; // 出発駅p, 到着駅q, 値の種類r
      if (r)       // r==1なら最短時間
        cout << T[p - 1][r - 1] << endl;
      else
        cout << C[p - 1][r - 1] << endl;
    }
  }

  return 0;
}