Problem p03411 (C++)

Buggy submission (status: Runtime Error):
// Power Of Ninja Go
#include <bits/stdc++.h>
// #ifdef atom #else #endif
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
#define X first
#define Y second
#define vi vector<int>
#define vii vector<ii>
#define pb push_back
const int maxn = 105;
ii R[maxn], B[maxn];
vi adj[2 * maxn + 2];
int res[maxn][maxn];
int p[maxn];
int vis[maxn];
int s, t;
int augment(int u, int minnow) {
  if (u == s)
    return minnow;
  if (p[u] == -1)
    return 0;
  int cap = augment(p[u], min(minnow, res[p[u]][u]));
  res[p[u]][u] -= cap;
  res[u][p[u]] += cap;
  return cap;
}
int main() {
  // #ifndef atom freopen(".in", "r", stdin); freopen(".out", "w", stdout);
  // #endif
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d %d", &R[i].X, &R[i].Y);
  for (int i = 1; i <= n; i++)
    scanf("%d %d", &B[i].X, &B[i].Y);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (R[i].X < B[j].X && R[i].Y < B[j].Y) {
        adj[i].pb(n + j);
        adj[n + j].pb(i);
        res[i][n + j] = 1;
      }
    }
  }
  for (int i = 1; i <= n; i++)
    adj[0].pb(i), res[0][i] = 1, adj[i].pb(0);
  for (int i = n + 1; i <= 2 * n; i++)
    adj[i].pb(2 * n + 1), res[i][2 * n + 1] = 1, adj[2 * n + 1].pb(i);
  int mf = 0;
  s = 0, t = 2 * n + 1;
  while (true) {
    memset(p, -1, sizeof p);
    memset(vis, 0, sizeof vis);
    queue<int> Q;
    Q.push(0);
    vis[0] = 1;
    while (!Q.empty()) {
      int u = Q.front();
      Q.pop();
      // printf("%d\n", u);
      if (u == t)
        break;
      for (auto v : adj[u]) {
        if (!vis[v] && res[u][v]) {
          vis[v] = 1;
          p[v] = u;
          Q.push(v);
        }
      }
    }
    int f = augment(t, 1e9);
    if (!f)
      break;
    mf += f;
  }
  printf("%d\n", mf);
}


Fixed submission:
// Power Of Ninja Go
#include <bits/stdc++.h>
// #ifdef atom #else #endif
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
#define X first
#define Y second
#define vi vector<int>
#define vii vector<ii>
#define pb push_back
const int maxn = 105;
ii R[maxn], B[maxn];
vi adj[2 * maxn + 2];
int res[2 * maxn + 2][2 * maxn + 2];
int p[2 * maxn + 2];
int vis[2 * maxn + 2];
int s, t;
int augment(int u, int minnow) {
  if (u == s)
    return minnow;
  if (p[u] == -1)
    return 0;
  int cap = augment(p[u], min(minnow, res[p[u]][u]));
  res[p[u]][u] -= cap;
  res[u][p[u]] += cap;
  return cap;
}
int main() {
  // #ifndef atom freopen(".in", "r", stdin); freopen(".out", "w", stdout);
  // #endif
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d %d", &R[i].X, &R[i].Y);
  for (int i = 1; i <= n; i++)
    scanf("%d %d", &B[i].X, &B[i].Y);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (R[i].X < B[j].X && R[i].Y < B[j].Y) {
        adj[i].pb(n + j);
        adj[n + j].pb(i);
        res[i][n + j] = 1;
      }
    }
  }
  for (int i = 1; i <= n; i++)
    adj[0].pb(i), res[0][i] = 1, adj[i].pb(0);
  for (int i = n + 1; i <= 2 * n; i++)
    adj[i].pb(2 * n + 1), res[i][2 * n + 1] = 1, adj[2 * n + 1].pb(i);
  int mf = 0;
  s = 0, t = 2 * n + 1;
  while (true) {
    memset(p, -1, sizeof p);
    memset(vis, 0, sizeof vis);
    queue<int> Q;
    Q.push(0);
    vis[0] = 1;
    while (!Q.empty()) {
      int u = Q.front();
      Q.pop();
      // printf("%d\n", u);
      if (u == t)
        break;
      for (auto v : adj[u]) {
        if (!vis[v] && res[u][v]) {
          vis[v] = 1;
          p[v] = u;
          Q.push(v);
        }
      }
    }
    int f = augment(t, 1e9);
    if (!f)
      break;
    mf += f;
  }
  printf("%d\n", mf);
}