Problem p02378 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

const int MAX_V = 101;
const int MAX_X = 101;
const int MAX_Y = 101;

class Edge {
public:
  int to, cap, rev;
};

typedef vector<vector<Edge>> AdjList;
AdjList G(MAX_V);
bool used[MAX_V];

void addEdge(int from, int to, int cap) {
  G[from].emplace_back(Edge{to, cap, static_cast<int>(G[to].size())});
  G[to].emplace_back(Edge{from, 0, static_cast<int>(G[from].size() - 1)});
}

int dfs(int v, int t, int f) {
  if (v == t)
    return f;
  used[v] = true;
  rep(i, G[v].size()) {
    Edge &e = G[v][i];
    if (not used[e.to] && e.cap > 0) {
      int d = dfs(e.to, t, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int maxFlow(int s, int t) {
  int flow = 0;
  while (true) {
    memset(used, 0, sizeof(used));
    int f = dfs(s, t, INF);
    if (f == 0)
      return flow;
    flow += f;
  }
}

int bipartiteMatching(int x, int y, bool edge[MAX_X][MAX_Y]) {
  int s = x + y, t = s + 1; // set x : 0 ~ x-1, set y : x ~ x+y-1

  rep(i, x) addEdge(s, i, 1);     // s??¨??????x????????¶
  rep(i, y) addEdge(x + i, t, 1); //??????y??¨t????????¶

  rep(i, x) rep(j, y) if (edge[i][j])
      addEdge(i, x + j, 1); //??????x??¨??????y????????¶

  return maxFlow(s, t);
}

int main() {
  int x, y, e;
  cin >> x >> y >> e;

  bool edge[MAX_X][MAX_Y] = {0};
  rep(i, e) {
    int a, b;
    cin >> a >> b;
    edge[a][b] = 1;
  }
  cout << bipartiteMatching(x, y, edge) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

const int MAX_V = 210; // MAX_X + MAX_Y
const int MAX_X = 105;
const int MAX_Y = 105;

class Edge {
public:
  int to, cap, rev;
};

typedef vector<vector<Edge>> AdjList;
AdjList G(MAX_V);
bool used[MAX_V];

void addEdge(int from, int to, int cap) {
  G[from].emplace_back(Edge{to, cap, static_cast<int>(G[to].size())});
  G[to].emplace_back(Edge{from, 0, static_cast<int>(G[from].size() - 1)});
}

int dfs(int v, int t, int f) {
  if (v == t)
    return f;
  used[v] = true;
  rep(i, G[v].size()) {
    Edge &e = G[v][i];
    if (not used[e.to] && e.cap > 0) {
      int d = dfs(e.to, t, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int maxFlow(int s, int t) {
  int flow = 0;
  while (true) {
    memset(used, 0, sizeof(used));
    int f = dfs(s, t, INF);
    if (f == 0)
      return flow;
    flow += f;
  }
}

int bipartiteMatching(int x, int y, bool edge[MAX_X][MAX_Y]) {
  int s = x + y, t = s + 1; // set x : 0 ~ x-1, set y : x ~ x+y-1

  rep(i, x) addEdge(s, i, 1);     // s??¨??????x????????¶
  rep(i, y) addEdge(x + i, t, 1); //??????y??¨t????????¶

  rep(i, x) rep(j, y) if (edge[i][j])
      addEdge(i, x + j, 1); //??????x??¨??????y????????¶

  return maxFlow(s, t);
}

int main() {
  int x, y, e;
  cin >> x >> y >> e;

  bool edge[MAX_X][MAX_Y] = {0};
  rep(i, e) {
    int a, b;
    cin >> a >> b;
    edge[a][b] = 1;
  }
  cout << bipartiteMatching(x, y, edge) << endl;
}