Problem p03411 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef int FLOW;
const int MAX_V = 110;
const FLOW INF = 10000;

struct Edge {
  int rev, from, to;
  FLOW cap, icap;
  Edge(int r, int f, int t, FLOW c) : rev(r), from(f), to(t), cap(c), icap(c) {}
};
struct Graph {
  int V;
  vector<Edge> list[MAX_V];

  Graph(int n = 0) : V(n) { rep(i, MAX_V) list[i].clear(); }
  void init(int n = 0) {
    V = n;
    rep(i, MAX_V) list[i].clear();
  }
  void resize(int n = 0) { V = n; }
  void reset() {
    rep(i, V) rep(j, list[i].size()) list[i][j].cap = list[i][j].cap;
  }
  inline vector<Edge> &operator[](int i) { return list[i]; }
  Edge &redge(Edge e) {
    if (e.from != e.to)
      return list[e.to][e.rev];
    else
      return list[e.to][e.rev + 1];
  }
  void addedge(int from, int to, FLOW cap) {
    list[from].push_back(Edge((int)list[to].size(), from, to, cap));
    list[to].push_back(Edge((int)list[from].size() - 1, to, from, 0));
  }
};
int level[MAX_V], iter[MAX_V];
void bfs(Graph G, int s) {
  memset(level, -1, sizeof(level));
  level[s] = 0;
  queue<int> q;
  level[s] = 0;
  q.push(s);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    rep(i, G[v].size()) {
      Edge &e = G[v][i];
      if (e.cap > 0 && level[e.to] < 0) {
        level[e.to] = level[v] + 1;
        q.push(e.to);
      }
    }
  }
}
int dfs(Graph &G, int v, int t, int f) {
  if (v == t)
    return f;
  for (int &i = iter[v]; i < (int)G[v].size(); i++) {
    Edge &e = G[v][i], &re = G.redge(e);
    ;
    if (e.cap > 0 && level[v] < level[e.to]) {
      FLOW d = dfs(G, e.to, t, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        re.cap += d;
        return d;
      }
    }
  }
  return 0;
}
int maxflow(Graph &G, int s, int t) {
  int flow = 0;
  while (true) {
    bfs(G, s);
    if (level[t] < 0)
      return flow;
    memset(iter, 0, sizeof(iter));
    int f;
    while ((f = dfs(G, s, t, INF)) > 0)
      flow += f;
  }
  return 0;
}
int main() {
  int n, x, y;
  cin >> n;
  Graph G(n + n + 2);
  vector<pair<int, int>> red(n);
  rep(i, n) cin >> red[i].first >> red[i].second;
  rep(i, n) {
    cin >> x >> y;
    rep(j, n) if (red[j].first < x && red[j].second < y) G.addedge(i, j + n, 1);
  }
  rep(i, n) {
    G.addedge(n + n, i, 1);
    G.addedge(i + n, n + n + 1, 1);
  }
  printf("%d", maxflow(G, n + n, n + n + 1));
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef int FLOW;
const int MAX_V = 210;
const FLOW INF = 10000;

struct Edge {
  int rev, from, to;
  FLOW cap, icap;
  Edge(int r, int f, int t, FLOW c) : rev(r), from(f), to(t), cap(c), icap(c) {}
};
struct Graph {
  int V;
  vector<Edge> list[MAX_V];

  Graph(int n = 0) : V(n) { rep(i, MAX_V) list[i].clear(); }
  void init(int n = 0) {
    V = n;
    rep(i, MAX_V) list[i].clear();
  }
  void resize(int n = 0) { V = n; }
  void reset() {
    rep(i, V) rep(j, list[i].size()) list[i][j].cap = list[i][j].cap;
  }
  inline vector<Edge> &operator[](int i) { return list[i]; }
  Edge &redge(Edge e) {
    if (e.from != e.to)
      return list[e.to][e.rev];
    else
      return list[e.to][e.rev + 1];
  }
  void addedge(int from, int to, FLOW cap) {
    list[from].push_back(Edge((int)list[to].size(), from, to, cap));
    list[to].push_back(Edge((int)list[from].size() - 1, to, from, 0));
  }
};
int level[MAX_V], iter[MAX_V];
void bfs(Graph G, int s) {
  memset(level, -1, sizeof(level));
  level[s] = 0;
  queue<int> q;
  level[s] = 0;
  q.push(s);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    rep(i, G[v].size()) {
      Edge &e = G[v][i];
      if (e.cap > 0 && level[e.to] < 0) {
        level[e.to] = level[v] + 1;
        q.push(e.to);
      }
    }
  }
}
int dfs(Graph &G, int v, int t, int f) {
  if (v == t)
    return f;
  for (int &i = iter[v]; i < (int)G[v].size(); i++) {
    Edge &e = G[v][i], &re = G.redge(e);
    ;
    if (e.cap > 0 && level[v] < level[e.to]) {
      FLOW d = dfs(G, e.to, t, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        re.cap += d;
        return d;
      }
    }
  }
  return 0;
}
int maxflow(Graph &G, int s, int t) {
  int flow = 0;
  while (true) {
    bfs(G, s);
    if (level[t] < 0)
      return flow;
    memset(iter, 0, sizeof(iter));
    int f;
    while ((f = dfs(G, s, t, INF)) > 0)
      flow += f;
  }
  return 0;
}
int main() {
  int n, x, y;
  cin >> n;
  Graph G(n + n + 2);
  vector<pair<int, int>> red(n);
  rep(i, n) cin >> red[i].first >> red[i].second;
  rep(i, n) {
    cin >> x >> y;
    rep(j, n) if (red[j].first < x && red[j].second < y) G.addedge(i, j + n, 1);
  }
  rep(i, n) {
    G.addedge(n + n, i, 1);
    G.addedge(i + n, n + n + 1, 1);
  }
  printf("%d", maxflow(G, n + n, n + n + 1));
  return 0;
}