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

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
#define MS(m, v) memset(m, v, sizeof(m))
#define D10 fixed << setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main() {
  int m, n;
  cin >> m >> n;
  vector<vi> graph(m, vi(m));
  vector<vector<pii>> v(m, vector<pii>(n, pii(0, INF)));
  REP(i, m) {
    int k;
    cin >> k;
    REP(j, k) {
      int s, t;
      string con;
      cin >> s >> con >> t;
      s--;
      if (con == "<=")
        chmin(v[i][s].second, t);
      else
        chmax(v[i][s].first, t);
    }
  }
  bool ans = false;
  bool ff = true;
  REP(i, m) REP(j, n) {
    if (v[i][j].first > v[i][j].second)
      ff = false;
  }
  if (ff) {
    REP(i, m) REP(j, m) {
      if (i == j)
        continue;
      bool f = true;
      REP(k, n) {
        if (v[i][k].second < v[j][k].first)
          f = false;
      }
      if (f)
        graph[j][i] = 1;
    }

    set<int> st;
    REP(j, m) st.insert(j);
    while (st.size()) {
      bool up = false;
      for (auto j : st) {
        bool f = true;
        for (auto k : st) {
          if (j == k)
            continue;
          if (graph[j][k] == 0)
            f = false;
        }
        if (f) {
          st.erase(j);
          up = true;
          break;
        }
      }
      if (!up)
        break;
    }
    if (st.size() == 0)
      ans = true;
  }
  puts(ans ? "Yes" : "No");
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
#define MS(m, v) memset(m, v, sizeof(m))
#define D10 fixed << setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main() {
  int m, n;
  cin >> m >> n;
  vector<vi> graph(n, vi(n));
  vector<vector<pii>> v(m, vector<pii>(n, pii(0, INF)));
  REP(i, m) {
    int k;
    cin >> k;
    REP(j, k) {
      int s, t;
      string con;
      cin >> s >> con >> t;
      s--;
      if (con == "<=")
        chmin(v[i][s].second, t);
      else
        chmax(v[i][s].first, t);
    }
  }
  bool ans = false;
  bool ff = true;
  REP(i, m) REP(j, n) {
    if (v[i][j].first > v[i][j].second)
      ff = false;
  }
  if (ff) {
    REP(i, n) REP(j, n) {
      if (i == j)
        continue;
      bool f = true;
      REP(k, n) {
        if (v[i][k].second < v[j][k].first)
          f = false;
      }
      if (f)
        graph[j][i] = 1;
    }

    set<int> st;
    REP(j, n) st.insert(j);
    while (st.size()) {
      bool up = false;
      for (auto j : st) {
        bool f = true;
        for (auto k : st) {
          if (j == k)
            continue;
          if (graph[j][k] == 0)
            f = false;
        }
        if (f) {
          st.erase(j);
          up = true;
          break;
        }
      }
      if (!up)
        break;
    }
    if (st.size() == 0)
      ans = true;
  }
  puts(ans ? "Yes" : "No");
  return 0;
}