Problem p03411 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)

class point_t {
public:
  bool operator<(const point_t &p) const {
    if (x == p.x)
      return y < p.y;

    return x < p.x;
  };

public:
  int x;
  int y;
};

#define MAX_V 100

int V;
std::vector<int> G[MAX_V];
int match[MAX_V];
int used[MAX_V];

void add_edge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}

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

  for (int i = 0; i < G[v].size(); i++) {
    int u = G[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 res = 0;

  memset(match, -1, sizeof(match));

  for (int v = 0; v < V; v++) {
    if (match[v] < 0) {
      memset(used, 0, sizeof(used));

      if (dfs(v))
        res++;
    }
  }
  return res;
}

int main(int argc, char **argv) {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  int N, c = 0;

  std::cin >> N;

  std::vector<point_t> reds(N), blues(N);

  for (auto &p : reds)
    std::cin >> p.x >> p.y;

  for (auto &p : blues)
    std::cin >> p.x >> p.y;

  std::sort(ALL(reds));
  std::sort(ALL(blues));

  for (int i = 0; i < N; i++) {
    const auto &p = reds[i];

    for (int j = 0; j < N; j++) {
      const auto &q = blues[j];

      if (p.x < q.x && p.y < q.y)
        add_edge(i, j + N);
    }
  }

  V = N + N;

  std::cout << bipartite_matching() << std::endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)

class point_t {
public:
  bool operator<(const point_t &p) const {
    if (x == p.x)
      return y < p.y;

    return x < p.x;
  };

public:
  int x;
  int y;
};

#define MAX_V 222

int V;
std::vector<int> G[MAX_V];
int match[MAX_V];
int used[MAX_V];

void add_edge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}

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

  for (int i = 0; i < G[v].size(); i++) {
    int u = G[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 res = 0;

  memset(match, -1, sizeof(match));

  for (int v = 0; v < V; v++) {
    if (match[v] < 0) {
      memset(used, 0, sizeof(used));

      if (dfs(v))
        res++;
    }
  }
  return res;
}

int main(int argc, char **argv) {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  int N, c = 0;

  std::cin >> N;

  std::vector<point_t> reds(N), blues(N);

  for (auto &p : reds)
    std::cin >> p.x >> p.y;

  for (auto &p : blues)
    std::cin >> p.x >> p.y;

  std::sort(ALL(reds));
  std::sort(ALL(blues));

  for (int i = 0; i < N; i++) {
    const auto &p = reds[i];

    for (int j = 0; j < N; j++) {
      const auto &q = blues[j];

      if (p.x < q.x && p.y < q.y)
        add_edge(i, j + N);
    }
  }

  V = N + N;

  std::cout << bipartite_matching() << std::endl;

  return 0;
}