Problem p03411 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define rpe(i, r, l) for (int i = (r); i >= (l); --i)
#define rpp(i, x, e, head) for (int i = head[x]; ~i; i = e[i].next)
#define dyes cerr << "yes" << endl
#define dbg(x) cerr << #x << "=" << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define pts puts("")
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
inline int read() {
  int f = 1, x = 0;
  char ch;
  do {
    ch = getchar();
    if (ch == '-')
      f = -1LL;
  } while (ch < '0' || ch > '9');
  do {
    x = x * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return f * x;
}
inline ll readll() {
  ll f = 1, x = 0;
  char ch;
  do {
    ch = getchar();
    if (ch == '-')
      f = -1LL;
  } while (ch < '0' || ch > '9');
  do {
    x = x * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return f * x;
}
template <class T> inline void chmax(T &a, T b) {
  if (a < b)
    a = b;
}
template <class T> inline void chmin(T &a, T b) {
  if (a > b)
    a = b;
}
inline void swap(int &a, int &b) {
  int c = a;
  a = b;
  b = c;
}
using namespace std;
#define mst(a, val) memset(a, val, sizeof(a))
#define pii pair<int, int>
#define piii pair<int, pair<int, int>>
#define mp(i, j) make_pair(i, j)
#define fi first
#define sc second
#define inf (0x3f3f3f3f)
#define infl (0x3f3f3f3f3f3f3f3fLL)
#define forvec(i, j)                                                           \
  for (vector<int>::iterator i = j.begin(); i != j.end(); ++i)
#define forvecv(i, j)                                                          \
  for (vector<int>::iterator i = --j.end(); i >= j.begin(); --i)
//=====================head end======================//
const int N = 1e3 + 10;
struct node {
  int next, to;
} e[N << 1];
int head[N], cnt;
inline void add(int u, int v) {
  e[cnt].to = v;
  e[cnt].next = head[u];
  head[u] = cnt++;
}
int n, x[N], y[N], c[N], d[N], vis[N], match[N];
inline bool dfs(int x) {
  rpp(i, x, e, head) {
    int v = e[i].to;
    if (!vis[v]) {
      vis[v] = 1;
      if (!match[v] || dfs(match[v])) {
        match[v] = x;
        return 1;
      }
    }
  }
  return 0;
}
int main() {
  mst(head, -1);
  n = read();
  rep(i, 1, n) x[i] = read(), y[i] = read();
  rep(i, 1, n) c[i] = read(), d[i] = read();
  rep(i, 1, n) rep(j, 1, n) {
    if (x[i] < c[j] && y[i] < d[j]) {
      add(i, j + n);
    }
  }
  int ans = 0;
  rep(i, 1, n) {
    mst(vis, 0);
    if (dfs(i))
      ++ans;
  }
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define rpe(i, r, l) for (int i = (r); i >= (l); --i)
#define rpp(i, x, e, head) for (int i = head[x]; ~i; i = e[i].next)
#define dyes cerr << "yes" << endl
#define dbg(x) cerr << #x << "=" << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define pts puts("")
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
inline int read() {
  int f = 1, x = 0;
  char ch;
  do {
    ch = getchar();
    if (ch == '-')
      f = -1LL;
  } while (ch < '0' || ch > '9');
  do {
    x = x * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return f * x;
}
inline ll readll() {
  ll f = 1, x = 0;
  char ch;
  do {
    ch = getchar();
    if (ch == '-')
      f = -1LL;
  } while (ch < '0' || ch > '9');
  do {
    x = x * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return f * x;
}
template <class T> inline void chmax(T &a, T b) {
  if (a < b)
    a = b;
}
template <class T> inline void chmin(T &a, T b) {
  if (a > b)
    a = b;
}
inline void swap(int &a, int &b) {
  int c = a;
  a = b;
  b = c;
}
using namespace std;
#define mst(a, val) memset(a, val, sizeof(a))
#define pii pair<int, int>
#define piii pair<int, pair<int, int>>
#define mp(i, j) make_pair(i, j)
#define fi first
#define sc second
#define inf (0x3f3f3f3f)
#define infl (0x3f3f3f3f3f3f3f3fLL)
#define forvec(i, j)                                                           \
  for (vector<int>::iterator i = j.begin(); i != j.end(); ++i)
#define forvecv(i, j)                                                          \
  for (vector<int>::iterator i = --j.end(); i >= j.begin(); --i)
//=====================head end======================//
const int N = 1e4 + 10;
struct node {
  int next, to;
} e[N << 1];
int head[N], cnt;
inline void add(int u, int v) {
  e[cnt].to = v;
  e[cnt].next = head[u];
  head[u] = cnt++;
}
int n, x[N], y[N], c[N], d[N], vis[N], match[N];
inline bool dfs(int x) {
  rpp(i, x, e, head) {
    int v = e[i].to;
    if (!vis[v]) {
      vis[v] = 1;
      if (!match[v] || dfs(match[v])) {
        match[v] = x;
        return 1;
      }
    }
  }
  return 0;
}
int main() {
  mst(head, -1);
  n = read();
  rep(i, 1, n) x[i] = read(), y[i] = read();
  rep(i, 1, n) c[i] = read(), d[i] = read();
  rep(i, 1, n) rep(j, 1, n) {
    if (x[i] < c[j] && y[i] < d[j]) {
      add(i, j + n);
    }
  }
  int ans = 0;
  rep(i, 1, n) {
    mst(vis, 0);
    if (dfs(i))
      ++ans;
  }
  printf("%d\n", ans);
  return 0;
}