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

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

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[700];
unsigned int d[150];

int main() {
  int n, m, k, p, q, r;
  while (cin >> n >> m) {
    if (n == 0 && m == 0)
      break;
    vector<E> cs;
    int ta, tb, tc, tt;
    rep(i, n) {
      cin >> ta >> tb >> tc >> tt;
      cs.push_back(E(ta, tb, tc, tt));
      cs.push_back(E(tb, ta, tc, tt));
    }

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

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

  return 0;
}

Error: -11

Fixed submission:

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

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[700];
unsigned int d[150];

int main() {
  int n, m, k, p, q, r;
  while (cin >> n >> m) {
    if (n == 0 && m == 0)
      break;
    vector<E> cs;
    int ta, tb, tc, tt;
    rep(i, n) {
      cin >> ta >> tb >> tc >> tt;
      cs[2 * i] = E(ta, tb, tc, tt);
      cs[2 * i + 1] = E(tb, ta, tc, tt);
    }

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

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

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

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int x[1000][1000][2], n, m, a, b, c, d, q, e;

int path(int n, int s, int g) {
  int p[1000];
  memset(p, 127, sizeof(p));
  p[s] = 0;
  e = min(n, 9);
  for (int i = 0; i < e; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        if (x[j][k][1] < 10000000) {
          p[k] = min(p[k], p[j] + x[j][k][1]);
        }
      }
    }
  }
  return p[g];
}

int score(int n, int s, int g) {
  int p[1000];
  memset(p, 127, sizeof(p));
  p[s] = 0;
  e = min(n, 9);
  for (int i = 0; i < e; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        if (x[j][k][0] < 10000000) {
          p[k] = min(p[k], p[j] + x[j][k][0]);
        }
      }
    }
  }
  return p[g];
}

int main() {
  while (true) {
    memset(x, 127, sizeof(x));
    cin >> m >> n;
    if (m == 0 && n == 0) {
      break;
    }
    for (int i = 0; i < m; i++) {
      cin >> a >> b >> c >> d;
      x[a][b][0] = c;
      x[b][a][0] = c;
      x[a][b][1] = d;
      x[b][a][1] = d;
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
      cin >> a >> b >> c;
      if (c == 0) {
        cout << score(n, a, b) << endl;
      } else {
        cout << path(n, a, b) << endl;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int x[1000][1000][2], n, m, a, b, c, d, q, e;

int path(int n, int s, int g) {
  int p[1000];
  memset(p, 127, sizeof(p));
  p[s] = 0;
  e = min(n, 10);
  for (int i = 0; i < e; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        if (x[j][k][1] < 10000000) {
          p[k] = min(p[k], p[j] + x[j][k][1]);
        }
      }
    }
  }
  return p[g];
}

int score(int n, int s, int g) {
  int p[1000];
  memset(p, 127, sizeof(p));
  p[s] = 0;
  e = min(n, 10);
  for (int i = 0; i < e; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        if (x[j][k][0] < 10000000) {
          p[k] = min(p[k], p[j] + x[j][k][0]);
        }
      }
    }
  }
  return p[g];
}

int main() {
  while (true) {
    memset(x, 127, sizeof(x));
    cin >> m >> n;
    if (m == 0 && n == 0) {
      break;
    }
    for (int i = 0; i < m; i++) {
      cin >> a >> b >> c >> d;
      x[a][b][0] = c;
      x[b][a][0] = c;
      x[a][b][1] = d;
      x[b][a][1] = d;
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
      cin >> a >> b >> c;
      if (c == 0) {
        cout << score(n, a, b) << endl;
      } else {
        cout << path(n, a, b) << endl;
      }
    }
  }
}
Problem p00200 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>

#define MIN(x, y) ((x < y) ? x : y)
#define INF (100000000)

using namespace std;

int date[2][105][105];
int answer[105]; // 最短距離
int subdate[105]; // 0...最短が決定,定数...次行ける,INF...次行けない
int n, m;
int a, b, cost, time;
int k;
int p, q, r;

int main() {
  while (true) {
    scanf("%d%d", &n, &m);
    for (int j = 0; j <= m; j++)
      for (k = 0; k <= m; k++)
        date[0][j][k] = date[1][j][k] = INF;
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < n; i++) {
      scanf("%d%d%d%d", &a, &b, &cost, &time);
      date[0][a][b] = date[0][b][a] = cost;
      date[1][a][b] = date[1][b][a] = time;
    }
    scanf("%d", &k);
    for (int i = 0; i < k; i++) {
      scanf("%d%d%d", &p, &q, &r);
      fill(subdate, subdate + 105, INF);
      answer[104] = p;
      answer[p] = 0;
      subdate[p] = 0;
      while (true) {
        answer[101] = -1;
        // 最後に更新した点から行けるところを更新
        // そして、最短経路が決まっているところから
        // 後ひと駅で行ける場所の中で最短を最短経路として決定する
        answer[103] = INF;
        for (int j = 1; j <= m; j++) {
          subdate[j] =
              MIN(subdate[j], answer[answer[104]] + date[r][answer[104]][j]);
        }
        for (int j = 1; j <= m; j++) {
          if (subdate[j] != 0 && answer[103] > subdate[j]) {
            answer[103] = subdate[j];
            answer[104] = j;
          }
        }
        if (answer[103] == INF)
          break;
        answer[answer[104]] = answer[103];
        subdate[answer[104]] = 0;
      }
      printf("%d\\n", answer[q]);
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>

using namespace std;

int main() {
  while (true) {
    int timedate[2][105][105];
    int n, m;
    memset(timedate, 0, sizeof(timedate));
    scanf("%d%d", &n, &m);
    if (n == 0 && m == 0)
      break;
    int a, b, cost, time;
    for (int i = 0; i < n; i++) {
      scanf("%d%d%d%d", &a, &b, &cost, &time);
      timedate[0][a][b] = cost;
      timedate[0][b][a] = cost;
      timedate[1][a][b] = time;
      timedate[1][b][a] = time;
    }
    int k;
    scanf("%d", &k);
    for (int i = 0; i < k; i++) {
      int p, q, r;
      int date[105];
      int omin = 1000000, jmin;
      fill(date, date + 100, -1);
      scanf("%d%d%d", &p, &q, &r);
      date[p] = 0;

      for (int u = 1; u < 100; u++) {
        omin = 1000000;
        jmin = 0;
        for (int j = 1; j < 100; j++) {
          if (date[j] != -1) {
            for (int o = 1; o < 101; o++) {
              if (timedate[r][j][o] != 0 && o != -1 &&
                  omin > date[j] + timedate[r][j][o] && date[o] == -1) {
                omin = date[j] + timedate[r][j][o];
                jmin = o;
              }
            }
          }
        }
        date[jmin] = omin;
        if (jmin == 0)
          break;
      }
      printf("%d\\n", date[q]);
    }
  }
  return 0;
}
Problem p00200 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#define INF 100000000
using namespace std;
int min(int a, int b) { return a < b ? a : b; }
int main() {
  int n, m;
  while (cin >> n >> m) {
    if (n == 0 && m == 0)
      break;
    int d0[m + 1][m + 1], d1[m + 1][m + 1];
    for (int i = 1; i <= m; i++) {
      for (int j = 1; j <= m; j++) {
        d0[i][j] = INF;
        d1[i][j] = INF;
      }
    }
    int a, b, cost, time;
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> cost >> time;
      d0[a][b] = cost;
      d0[b][a] = cost;
      d1[a][b] = time;
      d1[b][a] = time;
    }
    for (int i = 1; i <= m; i++) {
      for (int j = 1; j <= m; j++) {
        for (int k = 1; k <= m; k++) {
          d0[j][k] = min(d0[j][k], d0[j][i] + d0[i][k]);
          d1[j][k] = min(d1[j][k], d1[j][i] + d1[i][k]);
        }
      }
    }
    int s, p, q, r;
    cin >> s;
    for (int i = 0; i < s; i++) {
      cin >> p >> q >> r;
      if (p == q)
        cout << 0 << endl;
      else if (r == 0)
        cout << d0[p][q] << endl;
      else
        cout << d1[p][q] << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int line[101][101], c[101][101], t[101][101];
int stop[101] = {0};
int ls[101] = {0};
int route_cost(int p, int q) {
  int top = -1;
  for (int i = 0; i < ls[p]; i++) {
    // cout << line[p][i] << endl;
    if (stop[line[p][i]] != 0)
      continue;
    stop[p]++;
    if (q == line[p][i]) {
      stop[p] = 0;
      return c[p][q];
    }
    int h = route_cost(line[p][i], q) + c[p][line[p][i]];
    if (top < 0 || top > h) {
      top = h + c[p][line[p][i]];
    }
  }
  stop[p] = 0;
  return top;
}
int route_time(int p, int q) {
  int top = -1;
  for (int i = 0; i < ls[p]; i++) {
    // cout << "P " << p << endl;
    // cout << line[p][i] << endl;
    if (stop[line[p][i]] != 0)
      continue;
    stop[p]++;
    if (q == line[p][i]) {
      stop[p] = 0;
      return t[p][q];
    }
    int h = route_time(line[p][i], q) + t[p][line[p][i]];
    if (top < 0 || top > h) {
      top = h;
      // cout << 'O' << endl;
    }
  }
  stop[p] = 0;
  return top;
}
int main() {
  int n, m;
  int a, b, cost, time;
  while (cin >> n >> m) {
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> cost >> time;
      line[a][ls[a]] = b;
      ls[a]++;
      line[b][ls[b]] = a;
      ls[b]++;
      c[a][b] = cost;
      c[b][a] = cost;
      t[a][b] = time;
      t[b][a] = time;
      // cout << "line " << line[a][ls[a]-1] << ' ' << line[b][ls[b]-1] << endl;
    }
    int k;
    cin >> k;
    int p, q, r;
    for (int i = 0; i < k; i++) {
      cin >> p >> q >> r;
      if (r == 0)
        cout << route_cost(p, q) << endl;
      else if (r == 1)
        cout << route_time(p, q) << endl;
    }
  }
  return 0;
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#define INF 2 << 23
using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m) {
    if (n == 0 && m == 0)
      break;
    int cost[m + 1][m + 1];
    int time[m + 1][m + 1];

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

    for (int i = 0; i < n; i++) {
      int a, b;
      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 = 1; i <= m; i++)       // ?????±????????????
      for (int j = 1; j <= m; j++)     // ????§???????
        for (int k = 1; k <= m; k++) { // ??????
          cost[j][k] = min(cost[j][k], cost[j][i] + cost[i][k]);
          time[j][k] = min(time[j][k], time[j][i] + time[i][k]);
        }

    int k;
    cin >> k;
    int p, q, r;
    for (int i = 0; i < k; i++) {
      cin >> p >> q >> r;
      switch (r) {
      case 0:
        cout << cost[p][q] << endl;
        break;
      case 1:
        cout << time[p][q] << endl;
        break;
      default:
        break;
      }
    }
  }
}

Error: 0

Fixed submission:

#include <iostream>
#define INF 2 << 20
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int cost[m + 1][m + 1];
  int time[m + 1][m + 1];

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

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

  for (int i = 1; i <= m; i++)       // ?????±????????????
    for (int j = 1; j <= m; j++)     // ????§???????
      for (int k = 1; k <= m; k++) { // ??????
        cost[j][k] = min(cost[j][k], cost[j][i] + cost[i][k]);
        time[j][k] = min(time[j][k], time[j][i] + time[i][k]);
      }

  int k;
  cin >> k;
  int p, q, r;
  while (cin >> p >> q) {
    if (p == 0 && q == 0)
      break;
    cin >> r;
    switch (r) {
    case 0:
      cout << cost[p][q] << endl;
      break;
    case 1:
      cout << time[p][q] << endl;
      break;
    default:
      break;
    }
  }
  return 0;
}
Problem p00200 (C++) — buggy submission, verdict: Runtime Error

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

array<array<int, 210>, 210> costs;
array<array<int, 210>, 210> times;

int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    for (auto &ar : costs)
      ar.fill(1000000);
    for (auto &ar : times)
      ar.fill(1000000);
    for (int i = 0; i < n; i++) {
      int a, b, c, t;
      cin >> a >> b >> c >> t;
      a--;
      b--;
      costs[a][b] = costs[b][a] = c;
      times[a][b] = times[b][a] = t;
    }
    for (int i = 0; i < m; i++) {
      costs[i][i] = 0;
      times[i][i] = 0;
    }

    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        for (int k = 0; k < m; k++) {
          costs[j][k] = min(costs[j][k], costs[j][i] + costs[i][k]);
          times[j][k] = min(times[j][k], times[j][i] + times[i][k]);
        }
      }
    }
    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 << costs[p][q] << endl;
      } else {
        cout << times[p][q] << endl;
      }
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

array<array<int, 210>, 210> costs;
array<array<int, 210>, 210> times;

int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    for (auto &ar : costs)
      ar.fill(1000000);
    for (auto &ar : times)
      ar.fill(1000000);
    for (int i = 0; i < n; i++) {
      int a, b, c, t;
      cin >> a >> b >> c >> t;
      a--;
      b--;
      costs[a][b] = costs[b][a] = c;
      times[a][b] = times[b][a] = t;
    }
    for (int i = 0; i < n; i++) {
      costs[i][i] = 0;
      times[i][i] = 0;
    }

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

#include <algorithm>
#include <iostream>
const int INF = 1000000;

int map[101][101][2]; // a, b, cost, time;
int d[101];           // 始点からの最短距離
bool used[101];       // 使われたかのフラグ
int V;                // 頂点数

int dijkstra(int start, int end, bool flag) {
  std::fill(d, d + V + 1, INF);
  std::fill(used, used + V + 1, false);
  d[start] = 0;

  while (1) {
    int v = -1;
    for (int u = 1; u <= V; u++) {
      if (!used[u] && (v == -1 || d[u] < d[v]))
        v = u;
    }

    if (v == -1)
      break;

    used[v] = true;

    for (int u = 1; u <= V; u++) {
      d[u] = std::min(d[u], d[v] + map[v][u][flag]);
    }
  }

  return d[end];
}

int main() {
  int n, m; // track, station
  while (std::cin >> n >> m, n) {
    V = m;

    for (int i = 0; i < 101; i++) {
      for (int j = 0; j < 101; j++) {
        map[i][j][0] = (map[i][j][1] = INF);
      }
    }

    for (int i = n; i; i--) {
      int a, b, cost, time;
      std::cin >> a >> b >> cost >> time;
      map[a][b][0] = cost;
      map[a][b][1] = time;
      map[b][a][0] = cost;
      map[b][a][1] = time;
    }

    int k; // 取り合わせ数
    std::cin >> k;
    while (k--) {
      int p, q, r;
      std::cin >> p >> q >> r; // start, end, bool
      std::cout << dijkstra(p, q, r) << '\\n';
    }
  }
}

Error: 0

Fixed submission:

#include <iostream>
const int MAX_E = 300, MAX_V = 100, INF = 1000000;
struct edge {
  int from, to, time, cost;
};

edge es[MAX_E + 1];
int d[MAX_V + 1];
int n, m, k;

// 0: time 1: cost
int minimum_value(int type, int start, int end) {
  for (int i = 1; i <= m; i++)
    d[i] = INF;
  d[start] = 0;

  int res = 0;
  while (true) {
    bool update = false;
    for (int i = 0; i < n; i++) {
      edge e = es[i];
      int cost = type ? e.cost : e.time;
      if (d[e.from] != INF && d[e.to] > d[e.from] + cost) {
        d[e.to] = d[e.from] + cost;
        res = d[e.to];
        update = true;
      }
    }
    if (!update)
      break;
  }

  return res;
}

int main() {
  while (std::cin >> n >> m, n) {
    for (int i = 0; i < n; i++) {
      int from, to, time, cost;
      std::cin >> from >> to >> time >> cost;
      edge e;
      e.from = from, e.to = to, e.time = time, e.cost = cost;
      es[i] = e;
    }

    std::cin >> k;
    for (int j = 0; j < k; j++) {
      int start, end, type;
      std::cin >> start >> end >> type;
      std::cout << minimum_value(type, start, end) << std::endl;
    }
  }

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

#include <iostream>
using namespace std;

#define INF 10000000

// 0: cost , 1 :time
int d[2][101][101];

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

  while ((cin >> n >> m) && n) {
    for (i = 1; i <= m; i++) {
      for (j = 1; j <= m; j++) {
        d[0][i][j] = d[1][j][i] = INF;
      }
    }
    for (i = 0; i < n; i++) {
      cin >> a >> b >> cost >> time;
      d[0][a][b] = d[0][b][a] = cost;
      d[1][a][b] = d[1][b][a] = time;
    }

    for (k = 1; k <= m; k++) {
      for (i = 1; i <= m; i++) {
        for (j = 1; j <= m; j++) {
          for (r = 0; r < 2; r++) {
            if (d[r][i][j] > d[r][i][k] + d[r][k][j]) {
              d[r][j][i] = d[r][i][j] = d[r][i][k] + d[r][k][j];
            }
          }
        }
      }
    }

    cin >> k;
    while (k--) {
      cin >> p >> q >> r;
      cout << d[r][p][q] << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

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

class Edge {
public:
  int sid, cost, time;
  Edge(int s, int c, int t) {
    sid = s;
    cost = c;
    time = t;
  }
};

class Node {
public:
  static int mode;
  int sid, cost, time;
  bool visited;
  vector<Edge *> edge;

  bool operator()(Node *a, Node *b) {
    return Node::mode == 0 ? a->cost > b->cost : a->time > b->time;
  }
};
int Node::mode = 0;

int main() {
  Node node, station[100], *s;
  priority_queue<Node *, vector<Node *>, Node> pq(node);
  int n, m, s1, s2, i, cost, time, k, p, q;

  while (cin >> n >> m && n) {
    for (i = 1; i <= m; i++) {
      station[i].sid = i;
      station[i].edge.clear();
    }
    for (i = 0; i < n; i++) {
      cin >> s1 >> s2 >> cost >> time;
      station[s1].edge.push_back(new Edge(s2, cost, time));
      station[s2].edge.push_back(new Edge(s1, cost, time));
    }

    cin >> k;
    while (k--) {
      for (i = 1; i <= m; i++) {
        station[i].cost = 3000000;
        station[i].time = 3000000;
        station[i].visited = false;
      }
      cin >> p >> q >> Node::mode;
      s = &station[p];
      s->cost = 0;
      s->time = 0;
      pq = priority_queue<Node *, vector<Node *>, Node>(node);
      pq.push(s);
      while (!pq.empty()) {
        s = pq.top();
        pq.pop();
        if (s->sid == q)
          break;
        if (s->visited)
          continue;
        s->visited = true;
        for (vector<Edge *>::iterator e = s->edge.begin(); e != s->edge.end();
             e++) {
          Node *ds = &station[(*e)->sid];
          if (Node::mode == 0) {
            cost = s->cost + (*e)->cost;
            if (cost < ds->cost) {
              ds->cost = cost;
              pq.push(ds);
            }
          } else {
            time = s->time + (*e)->time;
            if (time < ds->time) {
              ds->time = time;
              pq.push(ds);
            }
          }
        }
      }
      cout << (Node::mode == 0 ? s->cost : s->time) << endl;
    }
  }

  return 0;
}