Problem p03411 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <vector>
#define INF 1000000001
#define EPS 1.0e-6
#define MAX_V 200

using namespace std;

typedef long long ll;

int n;

int akax[150];
int akay[150];
int aox[150];
int aoy[150];

// グラフをつくる
/*loop
s-t pathをさがす　なければ終了
あったらそれに沿って流す
グラフを更新
*/

struct edge {
  int to, cap, rev;
};

vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from, int to, int cap) {
  G[from].push_back(edge{to, cap, (int)G[to].size()});
  G[to].push_back(edge{from, 0, (int)G[from].size() - 1});
}

int dfs(int v, int t, int f) {
  if (v == t)
    return f;
  used[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    edge &e = G[v][i];
    if (!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 max_flow(int s, int t) {
  int flow = 0;
  for (;;) {
    for (int i = 0; i < MAX_V; i++) {
      used[i] = 0;
    }
    // memset(used, 0, sizeof(used));
    int f = dfs(s, t, INF);
    if (f == 0)
      return flow;
    flow += f;
  }
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> akax[i] >> akay[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> aox[i] >> aoy[i];
  }

  for (int i = 0; i < n; i++) {
    add_edge(2 * n, i, 1);
  }

  for (int i = 0; i < n; i++) {
    add_edge(n + i, 2 * n + 1, 1);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (akax[i] < aox[j] && akay[i] < aoy[j]) {
        add_edge(i, n + j, 1);
      }
    }
  }

  cout << max_flow(2 * n, 2 * n + 1) << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <vector>
#define INF 1000000001
#define EPS 1.0e-6
#define MAX_V 300

using namespace std;

typedef long long ll;

int n;

int akax[150];
int akay[150];
int aox[150];
int aoy[150];

// グラフをつくる
/*loop
s-t pathをさがす　なければ終了
あったらそれに沿って流す
グラフを更新
*/

struct edge {
  int to, cap, rev;
};

vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from, int to, int cap) {
  G[from].push_back(edge{to, cap, (int)G[to].size()});
  G[to].push_back(edge{from, 0, (int)G[from].size() - 1});
}

int dfs(int v, int t, int f) {
  if (v == t)
    return f;
  used[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    edge &e = G[v][i];
    if (!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 max_flow(int s, int t) {
  int flow = 0;
  for (;;) {
    for (int i = 0; i < MAX_V; i++) {
      used[i] = 0;
    }
    // memset(used, 0, sizeof(used));
    int f = dfs(s, t, INF);
    if (f == 0)
      return flow;
    flow += f;
  }
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> akax[i] >> akay[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> aox[i] >> aoy[i];
  }

  for (int i = 0; i < n; i++) {
    add_edge(2 * n, i, 1);
  }

  for (int i = 0; i < n; i++) {
    add_edge(n + i, 2 * n + 1, 1);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (akax[i] < aox[j] && akay[i] < aoy[j]) {
        add_edge(i, n + j, 1);
      }
    }
  }

  cout << max_flow(2 * n, 2 * n + 1) << endl;

  return 0;
}