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

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
#define se second
#define fi first
using namespace std;
typedef pair<pair<double, int>, pair<int, int>> P;
struct edge {
  int to, lim;
  double dist;
};
int n, m, st, go, a1, a2, a3, a4;
double d[31][31][31];
int dx[] = {-1, 0, 1};
vector<edge> v[31];
int main() {
  while (cin >> n >> m, n) {
    r(i, 31) v[i].clear();
    r(i, 31) r(j, 31) r(k, 31) d[i][j][k] = 1e12;
    cin >> st >> go;
    r(i, m) {
      edge e;
      cin >> a1 >> a2 >> a3 >> a4;
      e.to = a2, e.dist = a3, e.lim = a4;
      v[a1].push_back(e);
      e.to = a1;
      v[a2].push_back(e);
    }
    priority_queue<P, vector<P>, greater<P>> q;
    P xt;
    xt.fi.fi = 0, xt.fi.se = 0, xt.se.fi = st, xt.se.se = -1;
    q.push(xt);
    while (!q.empty()) {
      P p = q.top();
      q.pop();
      int cur = p.se.fi, pp = p.se.se;
      if (cur == go && p.fi.se == 1) {
        printf("%.9f\\n", p.fi.fi);
        goto L;
      }
      r(i, v[cur].size()) {
        edge e = v[cur][i];
        if (e.to != p.se.se)
          r(j, 3) {
            int x = p.fi.se + dx[j];
            if (0 < x && x < 31 && x <= e.lim) {
              if (d[e.to][pp][x] > 1.0 * e.dist / x + p.fi.fi) {
                d[e.to][pp][x] = 1.0 * e.dist / x + p.fi.fi;
                P xt;
                xt.fi.fi = d[e.to][pp][x], xt.fi.se = x, xt.se.fi = e.to,
                xt.se.se = cur;
                q.push(xt);
              }
            }
          }
      }
    }
    cout << "unreachable" << endl;
  L:;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
#define se second
#define fi first
using namespace std;
typedef pair<int, int> P;
struct edge {
  int to, lim;
  double dist;
};
int n, m, st, go, a1, a3, a2, a4;
double d[31][31];
int dx[] = {-1, 0, 1};
vector<edge> v[31];
int main() {
  while (cin >> n >> m, n) {
    r(i, 31) v[i].clear();
    r(i, 31) r(j, 31) if (d[i][j] != 1e12) d[i][j] = 1e12;
    cin >> st >> go;
    r(i, m) {
      edge e;
      scanf("%d%d%d%d", &a1, &a2, &a3, &a4);
      e.to = a2, e.dist = a3, e.lim = a4;
      v[a1].push_back(e);
      e.to = a1;
      v[a2].push_back(e);
    }
    priority_queue<P> q;
    d[st][0] = 0;
    P xtt;
    xtt.fi = 0, xtt.se = st * 1000 + 0;
    q.push(xtt);
    while (!q.empty()) {
      P p = q.top();
      q.pop();
      int cur = p.se / 1000, xx = p.se % 1000;
      r(i, v[cur].size()) {
        edge e = v[cur][i];
        if (e.to != xx)
          r(j, 3) {
            int x = p.fi + dx[j];
            if (0 < x && x <= e.lim) {
              double t = e.dist / x + d[cur][p.fi];
              if (d[e.to][x] > t) {
                d[e.to][x] = t;
                P xt;
                xt.fi = x, xt.se = cur + e.to * 1000;
                q.push(xt);
              }
            }
          }
      }
    }
    if (d[go][1] == 1e12)
      cout << "unreachable" << endl;
    else
      printf("%.9f\\n", d[go][1]);
  }
}
Problem p00743 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define loop(n, i) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

struct State {
  int i, prev, sp;
  double cost;
};

bool operator>(const State &a, const State &b) { return a.cost > b.cost; }

const double INF = 1 << 29;

int main() {
  while (1) {
    int n, m, s, g;
    cin >> n >> m >> s >> g;
    if (!n)
      break;
    s--, g--;

    vector<vector<double>> dist(n, vector<double>(n, INF));
    vector<vector<int>> lim(n, vector<int>(n));

    while (m--) {
      int x, y, d, c;
      cin >> x >> y >> d >> c;
      x--, y--;
      dist[x][y] = dist[y][x] = d;
      lim[x][y] = lim[y][x] = c;
    }

    priority_queue<State, vector<State>, greater<State>> Q;
    Q.push({s, 39, 0, 0});

    int vis[40][40][40] = {};
    double ans = INF;
    while (Q.size()) {
      auto e = Q.top();
      Q.pop();
      if (vis[e.i][e.sp][e.prev])
        continue;
      vis[e.i][e.sp][e.prev] = 1;
      if (e.i == g && e.sp == 1)
        ans = min(ans, e.cost);
      loop(n, i) loop(3, d) {
        int sp = e.sp - 1 + d;
        if (dist[e.i][i] == INF || i == e.prev || sp < 1 || sp > lim[e.i][i])
          continue;
        Q.push({i, e.i, sp, e.cost + dist[e.i][i] / sp});
      }
    }
    if (ans != INF)
      cout << setprecision(12) << fixed << ans << endl;
    else
      cout << "unreachable" << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>

#define loop(n, i) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

struct State {
  int i, prev, sp;
  double cost;
};

bool operator>(const State &a, const State &b) { return a.cost > b.cost; }

const double INF = 1 << 29;

int main() {
  while (1) {
    int n, m, s, g;
    cin >> n >> m >> s >> g;
    s--, g--;

    vector<vector<double>> dist(n, vector<double>(n, INF));
    vector<vector<int>> lim(n, vector<int>(n));

    while (m--) {
      int x, y, d, c;
      cin >> x >> y >> d >> c;
      x--, y--;
      dist[x][y] = dist[y][x] = d;
      lim[x][y] = lim[y][x] = c;
    }

    priority_queue<State, vector<State>, greater<State>> Q;
    Q.push({s, -1, 0, 0});

    pair<int, int> debug[40][40];

    int vis[40][40][40] = {};
    double ans = INF;
    while (Q.size()) {
      auto e = Q.top();
      Q.pop();
      if (vis[e.i][e.sp][e.prev])
        continue;
      vis[e.i][e.sp][e.prev] = 1;
      if (e.i == g && e.sp == 1)
        ans = min(ans, e.cost);
      loop(n, i) loop(3, d) {
        int sp = e.sp - 1 + d;
        if (dist[e.i][i] == INF || i == e.prev || sp < 1 || sp > lim[e.i][i])
          continue;
        Q.push({i, e.i, sp, e.cost + dist[e.i][i] / sp});
      }
    }
    if (ans != INF)
      cout << ans << endl;
    else
      cout << "unreachable" << endl;
  }
  return 0;
}
Problem p00744 (C++) — buggy submission, verdict: Runtime Error

#include <list>
#include <stdio.h>
#include <string.h>
int F(int x, int y) {
  if (!y)
    return x;
  return F(y, x % y);
}
typedef std::list<int> L;
L e[1002];
int m, n;
bool f[1002];
int G(int s, int d) {
  if (s == d)
    return 1;
  if (f[s])
    return 0;
  f[s] = 1;
  for (L::iterator i = e[s].begin(); i != e[s].end(); ++i) {
    if (G(*i, d)) {
      e[*i].push_back(s);
      e[s].erase(i);
      return 1;
    }
  }
  return 0;
}
int main() {
  int a[500], i, j, x;
  while (scanf("%d%d", &m, &n), m) {
    for (i = 0; i < m + n + 2; ++i)
      e[i].clear();
    for (i = 0; i < m; ++i)
      scanf("%d", &a[i]), e[m + n].push_back(i);
    for (j = 0; j < n; ++j) {
      scanf("%d", &x);
      for (i = 0; i < m; ++i)
        if (F(a[i], x) > 1)
          e[i].push_back(m + j);
      e[m + j].push_back(m + n + 1);
    }
    for (x = 0; memset(f, 0, sizeof(f)), G(m + n, m + n + 1);)
      ++x;
    printf("%d\\n", x);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <list>
#include <stdio.h>
#include <string.h>
int F(int x, int y) {
  if (!y)
    return x;
  return F(y, x % y);
}
typedef std::list<int> L;
L e[1002];
int m, n;
bool f[1002];
int G(int s, int d) {
  if (s == d)
    return 1;
  if (f[s])
    return 0;
  f[s] = 1;
  for (L::iterator i = e[s].begin(); i != e[s].end(); ++i) {
    if (G(*i, d)) {
      e[*i].push_back(s);
      e[s].erase(i);
      return 1;
    }
  }
  return 0;
}
int main() {
  int a[100], i, j, x;
  while (scanf("%d%d", &m, &n), m) {
    for (i = 0; i < m + n + 2; ++i)
      e[i].clear();
    for (i = 0; i < m; ++i)
      scanf("%d", &a[i]), e[m + n].push_back(i);
    for (j = 0; j < n; ++j) {
      scanf("%d", &x);
      for (i = 0; i < m; ++i)
        if (F(a[i], x) > 1)
          e[i].push_back(m + j);
      e[m + j].push_back(m + n + 1);
    }
    for (x = 0; memset(f, 0, sizeof(f)), G(m + n, m + n + 1);)
      ++x;
    printf("%d\\n", x);
  }
  return 0;
}
Problem p00744 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int gcd(int a, int b) {
  if (!b)
    return a;
  return gcd(b, a % b);
}
int b[500], r[500];
vector<int> E[1000];
bool used[1000];
int match[1000];

bool dfs(int u) {
  used[u] = true;
  for (int v : E[u]) {
    int w = match[v];
    if (w == -1 || (!used[w] && dfs(w))) {
      match[u] = v;
      match[v] = u;
      return true;
    }
  }
  return false;
}
int main() {
  int m, n;
  while (scanf("%d%d", &m, &n), m) {
    rep(i, 1000) E[i].clear();
    rep(i, m) scanf("%d", &b[i]);
    rep(i, n) scanf("%d", &r[i]);
    rep(i, m) rep(j, n) {
      if (gcd(b[i], r[j]) != 1)
        E[i].push_back(m + j);
    }
    memset(match, -1, sizeof(match));
    int ans = 0;
    rep(i, m) {
      if (match[i] == -1) {
        memset(used, 0, sizeof(used));
        if (dfs(i))
          ans++;
      }
    }
    printf("%d\\n", ans);
  }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int gcd(int a, int b) {
  if (!b)
    return a;
  return gcd(b, a % b);
}
int b[500], r[500];
vector<int> E[500];
bool used[1000];
int match[1000];

bool dfs(int u) {
  used[u] = true;
  for (int v : E[u]) {
    int w = match[v];
    if (w == -1 || (!used[w] && dfs(w))) {
      match[u] = v;
      match[v] = u;
      return true;
    }
  }
  return false;
}
int main() {
  int m, n;
  while (scanf("%d%d", &m, &n), m) {
    rep(i, 1000) E[i].clear();
    rep(i, m) scanf("%d", &b[i]);
    rep(i, n) scanf("%d", &r[i]);
    rep(i, m) rep(j, n) {
      if (gcd(b[i], r[j]) != 1)
        E[i].push_back(m + j);
    }
    memset(match, -1, sizeof(match));
    int ans = 0;
    rep(i, m) {
      if (match[i] == -1) {
        memset(used, 0, sizeof(used));
        if (dfs(i))
          ans++;
      }
    }
    printf("%d\\n", ans);
  }
}
Problem p00744 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

vector<int> blue, red, redpair, v;
vector<vector<int>> c;
/*blue[i]??§i?????????????????????????????°???,red[i]??§i?????????????????????????????°???,redpair[i]??§i??????????????????????????¨?????¢????????????????????????????????????????????????,v[i]??§i??????????????????????????????????????????????????????(1:?????????0:??????)
c[i][j]??§blue[i]??¨red[j]????????¢?????§???????????¨???*/
int m = 0, n = 0;

int gcd(int x, int y) {
  if (x % y == 0) {
    return y;
  }
  return gcd(y, x % y);
}

bool match(int x) {
  if (x == -1)
    return 1;
  for (int i = 0; i < n; i++) {
    if (c[x][i] == 1 && v[i] == 0) {
      v[i] = 1;
      if (match(redpair[i])) {
        redpair[i] = x;
        return 1;
      }
    }
  }
  return 0;
}

int main() {
  while (cin >> m >> n) {
    if (m == 0 && n == 0) {
      break;
    }
    blue.clear();
    red.clear();
    redpair.clear();
    v.clear();
    c.clear();
    for (int i = 0; i < m; i++) {
      int tmp = 0;
      cin >> tmp;
      blue.push_back(tmp);
    }
    for (int i = 0; i < n; i++) {
      int tmp = 0;
      cin >> tmp;
      red.push_back(tmp);
      redpair.push_back(-1); //-1??§?????¢??????????????¶????????¨???
      v.push_back(0);
    }
    for (int i = 0; i < m; i++) {
      c.push_back(vector<int>());
      for (int j = 0; j < n; j++) {
        c[i].push_back(gcd(blue[i], red[j]) != 1);
      }
    }
    int ans = 0;
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        v[j] = 0;
      }
      if (match(i)) {
        ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

vector<int> blue, red, redpair, v;
// blue[i]??§i?????????????????????????????°???,red[i]??§i?????????????????????????????°???,redpair[i]??§i??????????????????????????¨?????¢????????????????????????????????????????????????,v[i]??§i????????????????????????????????????????????????????????¨???(1:?????????0:??????)
int m = 0, n = 0;

int gcd(int x, int y) {
  if (x % y == 0) {
    return y;
  }
  return gcd(y, x % y);
}

bool match(int x) {
  if (x == -1)
    return 1;
  for (int i = 0; i < n; i++) {
    if (gcd(blue[x], red[i]) != 1 && v[i] == 0) {
      v[i] = 1;
      if (match(redpair[i])) {
        redpair[i] = x;
        return 1;
      }
    }
  }
  return 0;
}

int main() {
  while (cin >> m >> n) {
    if (m == 0 && n == 0) {
      break;
    }
    blue.clear();
    red.clear();
    redpair.clear();
    v.clear();
    for (int i = 0; i < m; i++) {
      int tmp = 0;
      cin >> tmp;
      blue.push_back(tmp);
    }
    for (int i = 0; i < n; i++) {
      int tmp = 0;
      cin >> tmp;
      red.push_back(tmp);
      redpair.push_back(-1); //-1??§?????¢??????????????¶????????¨???
      v.push_back(0);
    }
    int ans = 0;
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        v[j] = 0;
      }
      if (match(i)) {
        ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00744 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define pb push_back
#define mp make_pair
#define SZ(a) ((int)(a.size()))
#define F first
#define S second
typedef long long ll;
typedef pair<int, int> PI;

const int MAX_N = 600;
int a[MAX_N];
int b[MAX_N];
bool vis[MAX_N];
int match[MAX_N];
int n, m;

int gcd[500][500];
vector<int> G[500];

bool aug(int cv) {
  vis[cv] = 1;
  for (auto j : G[cv]) {
    if (match[j] == -1 || (!vis[match[j]] && aug(match[j]))) {
      match[j] = cv;
      return true;
    }
  }
  return false;
}

int main(int argc, char *argv[]) {
  while (cin >> m >> n, n) {
    rep(i, 500) G[i].clear();
    rep(i, m) cin >> a[i];
    rep(j, n) cin >> b[j];
    rep(i, m) rep(j, n) if (1 != __gcd(a[i], b[j])) G[i].pb(j);

    memset(match, -1, sizeof(match));
    int ans = 0;
    rep(i, m) {
      memset(vis, 0, sizeof(vis));
      ans += aug(i);
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define pb push_back
#define mp make_pair
#define SZ(a) ((int)(a.size()))
#define F first
#define S second
typedef long long ll;
typedef pair<int, int> PI;

const int MAX_N = 600;
int a[MAX_N];
int b[MAX_N];
bool vis[MAX_N];
int match[MAX_N];
int n, m;

bool aug(int cv) {
  vis[cv] = 1;
  rep(j, n) {
    if (__gcd(a[cv], b[j]) == 1)
      continue;
    if (match[j] == -1 || (!vis[match[j]] && aug(match[j]))) {
      match[j] = cv;
      return true;
    }
  }
  return false;
}

int main(int argc, char *argv[]) {
  while (cin >> m >> n, n) {
    rep(i, m) cin >> a[i];
    rep(j, n) cin >> b[j];
    memset(match, -1, sizeof(match));
    int ans = 0;
    rep(i, m) {
      memset(vis, 0, sizeof(vis));
      ans += aug(i);
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00744 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// Class.
vector<int> list[100000];
int N, M, E;
int match[100000];
bool used[100000];
int x[10000], y[10000];

bool DFS(int V) {
  used[V] = true;
  for (int i = 0; i < list[V].size(); i++) {
    int u = list[V][i];
    int w = match[u];
    if (w < 0 || !used[w] && DFS(w)) {
      match[V] = u;
      match[u] = V;
      return true;
    }
  }
  return false;
}

int supermatching() {
  int r = 0;
  memset(match, -1, sizeof(match));
  for (int j = 0; j < N + M; j++) {
    if (match[j] < 0) {
      memset(used, 0, sizeof(used));
      if (DFS(j)) {
        r++;
      }
    }
  }
  return r;
}

// main.
int main() {
  while (true) {
    for (int i = 0; i < 100000; i++) {
      list[i].clear();
    }
    cin >> N >> M;
    if (!N) {
      break;
    }
    for (int i = 0; i < N; i++) {
      cin >> x[i];
    }
    for (int i = 0; i < M; i++) {
      cin >> y[i];
    }
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < M; j++) {
        if (__gcd(x[i], y[j]) != 1) {
          list[i].push_back(j + N);
        }
      }
    }
    cout << supermatching() << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

// Class.
vector<int> list[100000];
int N, M, E;
int match[100000];
bool used[100000];
int x[10000], y[10000];

bool DFS(int V) {
  used[V] = true;
  for (int i = 0; i < list[V].size(); i++) {
    int u = list[V][i];
    int w = match[u];
    if (w < 0 || !used[w] && DFS(w)) {
      match[V] = u;
      match[u] = V;
      return true;
    }
  }
  return false;
}

int supermatching() {
  int r = 0;
  memset(match, -1, sizeof(match));
  for (int j = 0; j < N + M; j++) {
    if (match[j] < 0) {
      memset(used, 0, sizeof(used));
      if (DFS(j)) {
        r++;
      }
    }
  }
  return r;
}

// main.
int main() {
  while (true) {
    for (int i = 0; i < 100000; i++) {
      list[i].clear();
    }
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
      cin >> x[i];
    }
    for (int i = 0; i < M; i++) {
      cin >> y[i];
    }
    for (int i = 0; i < M; i++) {
      for (int j = 0; j < N; j++) {
        if (__gcd(x[i], y[j]) != 1) {
          list[i].push_back(j);
        }
      }
    }
    cout << supermatching() << endl;
  }
  return 0;
}
Problem p00744 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int m, n, B[500], R[500], P[500], C[500][500];

// P[] カード赤とペアになっている青のカード番号 割り当てなしで -1
// B[i] と R[j] がマッチ可能なとき C[i][j] = 1 不可能なとき 0

bool V[500];
// true ならカード赤に新しい割り当て先はない false なら不明

int gcd(int a, int b) {

  int c;

  while (a != 0) {

    c = a;
    a = b % a;
    b = c;
  }

  return b;
}

int judge(int i, int j) {

  if (gcd(B[i], R[j]) >= 2) {
    return 1;
  } else {
    return 0;
  }
}

bool match(int i) {

  if (i < 0) {
    return true;
  }

  for (int j = 0; j < n; j++) {

    if (C[i][j] == 0 || V[j]) {
      continue;
    }

    V[j] = true;

    if (match(P[j])) {

      P[j] = i;
      return true;
    }
  }

  return false;
}

int main() {

  while (cin >> m >> n && m != 0 && n != 0) {

    for (int i = 0; i < m; i++) {
      cin >> B[i];
    }
    for (int i = 0; i < n; i++) {
      cin >> R[i];
    }

    for (int i = 0; i < n; i++) {
      P[i] = -1;
    }

    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        C[i][j] = judge(i, j);
      }
    }

    int count = 0;

    for (int i = 0; i < m; i++) {

      for (int i = 0; i < n; i++) {
        V[i] = false;
      }

      if (match(i)) {
        count++;
      }
    }

    cout << count << endl;
  }
}

Error: TLE

Fixed submission:

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

int m, n, B[500], R[500], P[500];

// P[] カード赤とペアになっている青のカード番号 割り当てなしで -1

bool V[500];
// true ならカード赤に新しい割り当て先はない false なら不明

int gcd(int a, int b) {

  int c;

  while (a != 0) {

    c = a;
    a = b % a;
    b = c;
  }

  return b;
}

int judge(
    int i,
    int j) { // B[i] と R[j] がマッチ可能なとき judge( i, j ) = 1 不可能なとき 0

  if (gcd(B[i], R[j]) >= 2) {
    return 1;
  } else {
    return 0;
  }
}

bool match(int i) {

  if (i < 0) {
    return true;
  }

  for (int j = 0; j < n; j++) {

    if (judge(i, j) == 0 || V[j]) {
      continue;
    }

    V[j] = true;

    if (match(P[j])) {

      P[j] = i;
      return true;
    }
  }

  return false;
}

int main() {

  while (cin >> m >> n && m != 0 && n != 0) {

    for (int i = 0; i < m; i++) {
      cin >> B[i];
    }
    for (int i = 0; i < n; i++) {
      cin >> R[i];
    }

    for (int i = 0; i < n; i++) {
      P[i] = -1;
    }

    int count = 0;

    for (int i = 0; i < m; i++) {

      for (int i = 0; i < n; i++) {
        V[i] = false;
      }

      if (match(i)) {
        count++;
      }
    }

    cout << count << endl;
  }
}
Problem p00744 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

// ------ Variable ------ //

int N, M;

// ------ Greatest Common Divisor ------ //

int GCD(int a, int b) {
  if (a % b == 0) {
    return b;
  }
  if (b % a == 0) {
    return a;
  }

  if (a > b) {
    return GCD(a % b, b);
  }
  if (b > a) {
    return GCD(b % a, a);
  }
}

// ------ Bipartite Matching ------ //

vector<vector<int>> Graph;

vector<int> match;

vector<bool> used;

bool dfs(int v) {
  used[v] = true;

  for (int i = 0; i < Graph[v].size(); i++) {
    int u = Graph[v][i], w = match[u];

    if (w < 0 || !used[w] && dfs(w)) {
      match[v] = u;
      match[u] = v;

      return true;
    }
  }

  return false;
}

int Bipartite_Matching() {
  int Ans = 0;

  match = vector<int>(N + M, -1);

  for (int i = 0; i < N + M; i++) {
    if (match[i] < 0) {
      used = vector<bool>(N + M, 0);

      if (dfs(i)) {
        Ans++;
      }
    }
  }

  return Ans;
}

int main() {
  while (true) {
    cin >> N >> M;

    if (N == 0 && M == 0) {
      break;
    }

    Graph = vector<vector<int>>(N + M, vector<int>());

    vector<int> A(N);
    vector<int> B(M);

    for (int i = 0; i < N; i++) {
      cin >> A[i];
    }
    for (int i = 0; i < M; i++) {
      cin >> B[i];
    }

    for (int i = 0; i < N; i++) {
      for (int j = 0; j < M; j++) {
        if (GCD(A[i], B[j]) != 1) {
          Graph[i].push_back(N + j);
          Graph[N + j].push_back(i);
        }
      }
    }

    cout << Bipartite_Matching() << endl;
  }

  return 0;
}

Error: WA

Fixed submission:

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

using namespace std;

// ------ Variable ------ //

int N, M;

// ------ Greatest Common Divisor ------ //

int GCD(int a, int b) {
  if (a % b == 0) {
    return b;
  }
  if (b % a == 0) {
    return a;
  }

  if (a > b) {
    return GCD(a % b, b);
  }
  if (b > a) {
    return GCD(b % a, a);
  }
}

// ------ Bipartite Matching ------ //

vector<vector<int>> Graph;

vector<int> match;

vector<bool> used;

bool dfs(int v) {
  used[v] = true;

  for (int i = 0; i < Graph[v].size(); i++) {
    int u = Graph[v][i], w = match[u];

    if (w < 0 || !used[w] && dfs(w)) {
      match[v] = u;
      match[u] = v;

      return true;
    }
  }

  return false;
}

int Bipartite_Matching() {
  int Ans = 0;

  match = vector<int>(N + M, -1);

  for (int i = 0; i < N; i++) {
    if (match[i] < 0) {
      used = vector<bool>(N + M, 0);

      if (dfs(i)) {
        Ans++;
      }
    }
  }

  return Ans;
}

int main() {
  while (true) {
    cin >> N >> M;

    if (N == 0 && M == 0) {
      break;
    }

    Graph = vector<vector<int>>(N, vector<int>());

    vector<int> A(N);
    vector<int> B(M);

    for (int i = 0; i < N; i++) {
      cin >> A[i];
    }
    for (int i = 0; i < M; i++) {
      cin >> B[i];
    }

    for (int i = 0; i < N; i++) {
      for (int j = 0; j < M; j++) {
        if (GCD(A[i], B[j]) != 1) {
          Graph[i].push_back(j);
        }
      }
    }

    cout << Bipartite_Matching() << endl;
  }

  return 0;
}