Problem p00329 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

// #define int long long
#define rep(v, a, b) for (int v = (a); v < (b); v++)
#define rrep(v, a, b) for (int v = (b)-1; v >= (a); v--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

struct BipartiteMatching {
  int n;
  vector<vector<int>> g;
  vector<int> match;
  vector<bool> used, alive;
  BipartiteMatching(int n) : n(n), g(n), match(n), used(n), alive(n, true) {}
  void addEdge(int u, int v) {
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }
  int maximumMatching() {
    int cnt = 0;
    fill(match.begin(), match.end(), -1);
    for (int v = 0; v < n; v++) {
      if (!alive[v])
        continue;
      if (match[v] == -1) {
        fill(used.begin(), used.end(), false);
        if (augment(v))
          cnt++;
      }
    }
    return cnt;
  }
  bool augment(int v) {
    used[v] = true;
    for (int u : g[v]) {
      if (!alive[u])
        continue;
      int w = match[u];
      if (w == -1 || (!used[w] && augment(w))) {
        match[v] = u;
        match[u] = v;
        return true;
      }
    }
    return false;
  }
};

struct LexicographicallyBipartiteMatching : BipartiteMatching {
  LexicographicallyBipartiteMatching(int n) : BipartiteMatching(n) {}
  int maximumMatching() {
    for (int v = 0; v < n; v++)
      sort(g[v].begin(), g[v].end());
    int cnt = BipartiteMatching::maximumMatching();
    for (int v = 0; v < n; v++) {
      if (!alive[v] || match[v] == -1)
        continue;
      match[match[v]] = -1;
      match[v] = -1;
      fill(used.begin(), used.end(), false);
      augment(v);
      alive[match[v]] = 0;
      alive[v] = 0;
    }
    return cnt;
  }
};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  N--;
  vector<vector<int>> b(N, vector<int>(N));
  rep(v, 0, N) rep(u, 0, N) { cin >> b[v][u]; }

  LexicographicallyBipartiteMatching lbm(N + N);
  rep(v, 0, N) rep(u, 0, N) {
    if (b[v][u])
      lbm.addEdge(u, N + v);
  }
  int res = lbm.maximumMatching();
  dump(res);
  if (res == N) {
    cout << "yes" << endl;
    rep(v, 0, N) { cout << lbm.match[v] - N + 1 << endl; }
  } else {
    cout << "no" << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

// #define int long long
#define rep(v, a, b) for (int v = (a); v < (b); v++)
#define rrep(v, a, b) for (int v = (b)-1; v >= (a); v--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

struct BipartiteMatching {
  int n;
  vector<vector<int>> g;
  vector<int> match;
  vector<bool> used, alive;
  BipartiteMatching(int n) : n(n), g(n), match(n), used(n), alive(n, true) {}
  void addEdge(int u, int v) {
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }
  int maximumMatching() {
    int cnt = 0;
    fill(match.begin(), match.end(), -1);
    for (int v = 0; v < n; v++) {
      if (!alive[v])
        continue;
      if (match[v] == -1) {
        fill(used.begin(), used.end(), false);
        if (augment(v))
          cnt++;
      }
    }
    return cnt;
  }
  bool augment(int v) {
    used[v] = true;
    for (int u : g[v]) {
      if (!alive[u])
        continue;
      int w = match[u];
      if (w == -1 || (!used[w] && augment(w))) {
        match[v] = u;
        match[u] = v;
        return true;
      }
    }
    return false;
  }
};

struct LexicographicallyBipartiteMatching : BipartiteMatching {
  LexicographicallyBipartiteMatching(int n) : BipartiteMatching(n) {}
  int maximumMatching() {
    for (int v = 0; v < n; v++)
      sort(g[v].begin(), g[v].end());
    int cnt = BipartiteMatching::maximumMatching();
    for (int v = 0; v < n; v++) {
      if (!alive[v])
        continue;
      match[match[v]] = -1;
      match[v] = -1;
      fill(used.begin(), used.end(), false);
      augment(v);
      alive[match[v]] = 0;
      alive[v] = 0;
    }
    return cnt;
  }
};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  N--;
  vector<vector<int>> b(N, vector<int>(N));
  rep(v, 0, N) rep(u, 0, N) { cin >> b[v][u]; }

  LexicographicallyBipartiteMatching lbm(N + N);
  rep(v, 0, N) rep(u, 0, N) {
    if (b[v][u])
      lbm.addEdge(u, N + v);
  }
  int res = lbm.maximumMatching();
  dump(res);
  if (res == N) {
    cout << "yes" << endl;
    rep(v, 0, N) { cout << lbm.match[v] - N + 1 << endl; }
  } else {
    cout << "no" << endl;
  }
  return 0;
}