alexjercan/bugnet huggingface dataset:
Problem p01659 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

#define rep(i, x, y) for (int i = (x); i < (y); ++i)
#define mp(a, b) make_pair((a), (b))
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int, int> pii;
// template<typename T> using vec=std::vector<T>;

const int INF = 1 << 30;
const long long int INF_ = 1LL << 58;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}

void Solve() {
  int n;
  cin >> n;
  int ans = 0;
  priority_queue<int> que;
  rep(i, 0, n) {
    int a;
    cin >> a;
    while (!que.empty() && que.top() > a)
      que.pop();
    if (que.empty() || que.top() != a) {
      que.push(a);
      ++ans;
    }
  }
  cout << ans << endl;
}

int main() {
  std::ios::sync_with_stdio(false);
  // std::cin.tie(0);
  Solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define rep(i, x, y) for (int i = (x); i < (y); ++i)
#define mp(a, b) make_pair((a), (b))
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int, int> pii;
// template<typename T> using vec=std::vector<T>;

const int INF = 1 << 30;
const long long int INF_ = 1LL << 58;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}

vector<int> a;

int Rec(int l, int r, int h) {
  if (l == r)
    return 0;

  int mini = INF;
  rep(i, l, r) mini = min(mini, a[i]);
  int res = 1, x = -1;
  rep(i, l, r + 1) {
    if (a[i] > mini && x == -1)
      x = i;
    if (a[i] <= mini && x >= 0) {
      res += Rec(x, i, mini);
      x = -1;
    }
  }
  return min(r - l, res);
}

void Solve() {
  int n;
  cin >> n;
  rep(i, 0, n) {
    int in;
    cin >> in;
    if (a.empty() || a.back() != in)
      a.push_back(in);
  }
  a.push_back(0);

  cout << Rec(0, a.size() - 1, 0) << endl;
}

int main() {
  std::ios::sync_with_stdio(false);
  // std::cin.tie(0);
  Solve();
  return 0;
}
Problem p01659 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

int N;

int main() {
  while (cin >> N) {
    vector<int> v(N);
    for (int i = 0; i < N; i++)
      cin >> v[i];
    v.erase(unique(v.begin(), v.end()), v.end());

    int ans = 1;

    stack<int> st;
    st.push(v[0]);

    for (int i = 1; i < v.size(); i++) {
      if (v[i] > v[i - 1]) {
        ans++;
        st.push(v[i]);
      } else {
        while (!st.empty() && st.top() > v[i])
          st.pop();

        if (st.empty() || st.top() < v[i])
          ans++;
        st.push(v[i]);
      }
    }

    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

int N;

bool check(vector<int> v) {
  for (int i = 0; i < N; i++) {
    if (v[i] != 0)
      return true;
  }
  return false;
}

int main() {
  while (cin >> N) {
    vector<int> v(N + 1);
    for (int i = 0; i < N; i++)
      cin >> v[i];
    v[N] = 0;

    int ans = 0;

    while (check(v)) {
      for (int i = 0; i < N; i++) {
        int left = -1, right = 0;
        right = v[i + 1];

        if (v[i] > right) {
          int now = v[i];

          for (int j = i - 1; j >= 0; j--) {
            if (v[j] != now) {
              left = v[j];
              break;
            }
          }

          for (int j = i; j >= 0; j--) {
            if (v[j] != now)
              break;
            v[j] = max(right, left);
          }
          ans++;
        }
      }
    }

    cout << ans << endl;
  }
  return 0;
}
Problem p01659 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

static const double EPS = 1e-8;

int tx[] = {0, 1, 0, -1};
int ty[] = {-1, 0, 1, 0};

int main() {
  int N;
  while (~scanf("%d", &N)) {
    priority_queue<int> carpets;
    int count = 0;
    for (int i = 0; i < N; i++) {
      int height;
      scanf("%d", &height);
      count++;

      while (!carpets.empty()) {
        if (carpets.top() > height) {
          carpets.pop();
        } else if (carpets.top() == height) {
          count--;
          break;
        } else {
          break;
        }
      }
      carpets.push(height);
    }
    printf("%d\\n", count);
  }
}

Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

static const double EPS = 1e-8;

int tx[] = {0, 1, 0, -1};
int ty[] = {-1, 0, 1, 0};

int main() {
  int N;
  while (~scanf("%d", &N)) {
    set<int> has_carpet;
    int count = 0;
    for (int i = 0; i < N; i++) {
      int height;
      scanf("%d", &height);
      count++;

      if (has_carpet.count(height))
        count--;
      set<int>::iterator it =
          upper_bound(has_carpet.begin(), has_carpet.end(), height);
      has_carpet.erase(it, has_carpet.end());
      has_carpet.insert(height);
    }
    printf("%d\\n", count);
  }
}
Problem p01659 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  int a[200000];
  set<int> S;
  cin >> n;

  for (int i = 0; i < n; i++)
    cin >> a[i];

  int ans = 0;
  set<int>::iterator it;
  S.insert(0);
  it = --S.end();
  for (int i = 0; i < n; i++) {
    if (S.count(a[i]))
      ans++;
    else
      S.insert(a[i]);
    while (*--S.end() > a[i])
      S.erase(--S.end());
    ;
  }

  cout << n - ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  int a[200000];
  map<int, int> M;
  cin >> n;
  int maxans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (M[a[i]])
      maxans++;
    else
      M[a[i]]++;
  }

  int ans = 0;
  for (int i = 0; i < n - 1 && ans < maxans; i++) {
    if (a[i] == 0)
      continue;
    for (int j = i + 1; j < n; j++) {
      if (a[i] > a[j])
        break;
      if (a[i] == a[j])
        a[j] = 0, ans++;
    }
  }
  cout << n - ans << endl;

  return 0;
}
Problem p01659 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <set>

using namespace std;

int n, res, a[216000];
set<int> nums;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++) {
    nums.insert(a[i]);
    while (*nums.rbegin() > a[i]) {
      res++;
      nums.erase(*nums.rbegin());
    }
  }
  cout << res + nums.size() << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <set>

using namespace std;

int n, res, a[21600];
set<int> nums;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++) {
    nums.insert(a[i]);
    while (*nums.rbegin() > a[i]) {
      res++;
      nums.erase(*nums.rbegin());
    }
  }
  cout << res + nums.size() << endl;
  return 0;
}
Problem p01659 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
set<int> s;
int n, a, ans;

int main() {
  cin >> n;
  while (n--) {
    cin >> a;
    if (s.find(a) == s.end()) {
      ans++;
      s.insert(a);
    }
    set<int>::iterator ite = s.end();
    ite--;
    while (1) {
      if (*ite > a)
        s.erase(*ite);
      else
        break;
      ite--;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
set<int> s;
int n, a, ans;

int main() {
  cin >> n;
  while (n--) {
    cin >> a;
    if (s.find(a) == s.end()) {
      ans++;
      s.insert(a);
    }
    set<int>::iterator ite;
    for (ite = s.begin(); ite != s.end(); ite++)
      if (*ite > a)
        s.erase(*ite);
  }
  cout << ans << endl;
}
Problem p01659 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)

#define PB push_back
#define INF (1 << 29)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset(a, 0, sizeof(a))
const int dx[] = {-1, 0, 0, 1}, dy[] = {0, 1, -1, 0};

typedef long long int ll;

using namespace std;

int main() {
  int n;
  stack<int> st;
  cin >> n;
  vector<int> a(n);
  REP(i, n) { cin >> a[i]; }
  int ans = 0;
  st.push(a[0]);
  ans++;
  FOR(i, 1, n) {
    /*
    printf("a[%d] = %d\\n",i,a[i]);
    printf("Before: st.top = %d\\n",st.top());
    */
    if (st.top() < a[i]) {
      ans++;
      st.push(a[i]);
    } else if (st.top() == a[i]) {
    } else {
      while (!st.empty()) {
        st.pop();
        if (st.empty()) {
          ans++;
          break;
        }
        if (a[i] == st.top()) {
          st.pop();
          break;
        } else if (a[i] < st.top()) {
        } else if (a[i] > st.top()) {
          ans++;
          break;
        }
      }
      st.push(a[i]);
    }
    /*
    printf("After: st.top = %d\\n",st.top());
    printf("ans = %d\\n",ans);
    */
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)

#define PB push_back
#define INF (1 << 29)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset(a, 0, sizeof(a))
const int dx[] = {-1, 0, 0, 1}, dy[] = {0, 1, -1, 0};

typedef long long int ll;

using namespace std;

int main() {
  int n;
  stack<int> st;
  cin >> n;
  vector<int> a(n);
  REP(i, n) { cin >> a[i]; }
  int ans = 0;
  st.push(a[0]);
  ans++;
  FOR(i, 1, n) {
    /*
    printf("a[%d] = %d\\n",i,a[i]);
    printf("Before: st.top = %d\\n",st.top());
    */
    if (st.top() < a[i]) {
      ans++;
      st.push(a[i]);
    } else if (st.top() == a[i]) {
    } else {
      while (!st.empty()) {
        st.pop();
        if (a[i] == st.top()) {
          st.pop();
          break;
        } else if (a[i] < st.top()) {
          continue;
        } else if (a[i] > st.top()) {
          ans++;
          break;
        }
      }
      st.push(a[i]);
    }
    /*
    printf("After: st.top = %d\\n",st.top());
    printf("ans = %d\\n",ans);
    */
  }
  cout << ans << endl;
  return 0;
}
Problem p01659 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int N;
int a[200010];

int main() {
  cin >> N;
  for (int j = 0; j < N; ++j) {
    cin >> a[j];
  }

  stack<int> s;

  int cnt = 1;

  s.push(0);
  s.push(a[0]);
  for (int j = 1; j < N; ++j) {
    int t = s.top();
    while (t > a[j]) {
      s.pop();
      t = s.top();
    }
    if (t < a[j]) {
      ++cnt;
      s.push(a[j]);
    }
  }

  cout << cnt << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int N;
int a[200010];

int main() {
  cin >> N;
  for (int j = 0; j < N; ++j) {
    cin >> a[j];
  }

  stack<int> s;

  int cnt = 1;

  s.push(a[0]);
  for (int j = 1; j < N; ++j) {
    int t = s.top();
    while (t > a[j]) {
      s.pop();
      t = s.top();
    }
    if (t < a[j]) {
      ++cnt;
      s.push(a[j]);
    }
  }

  cout << cnt << endl;
  return 0;
}
Problem p01659 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <limits>
#include <vector>
using namespace std;
// ------ RMQ Class ------ //
template <typename Type> class RMQ {
private:
  int size_;
  vector<Type> dat;
  Type query_(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l)
      return numeric_limits<Type>::max();
    if (a <= l && r <= b)
      return dat[k];
    int lc = query_(a, b, 2 * k, l, (l + r) / 2);
    int rc = query_(a, b, 2 * k + 1, (l + r) / 2, r);
    return min(lc, rc);
  }

public:
  RMQ(int size__) {
    for (size_ = 1; size_ < size__; size_ <<= 1)
      ;
    dat.resize(size_ * 2, numeric_limits<Type>::max());
  }
  RMQ(vector<Type> v) {
    for (size_ = 1; size_ < dat.size(); size_ <<= 1)
      ;
    dat.resize(size_ * 2, numeric_limits<Type>::max());
    for (int i = 0; i < v.size(); i++)
      dat[i + size_] = v[i];
    for (int i = size_ - 1; i >= 1; i--)
      dat[i] = min(dat[2 * i], dat[2 * i + 1]);
  }
  int size() { return size_; }
  int ndat() { return numeric_limits<Type>::max(); }
  void update(int i, int x) {
    i += size_;
    dat[i] = x;
    while (i > 1)
      i >>= 1, dat[i] = min(dat[2 * i], dat[2 * i + 1]);
  }
  Type query(int l, int r) { return query_(l, r, 1, 0, size_); }
};
int n, ptr, ret, a[200000], b[200000], previ[200001];
int main() {
  scanf("%d", &n);
  ret = n;
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]), b[i] = a[i];
  sort(b, b + n);
  for (int i = 0; i < n; i++)
    ptr = lower_bound(b, b + n, a[i]) - b, a[i] = ptr + 1;
  for (int i = 1; i <= n; i++)
    previ[i] = -1;
  RMQ<int> r(n);
  for (int i = 0; i < n; i++)
    r.update(i, a[i]);
  for (int i = 0; i < n; i++) {
    if (previ[a[i]] != -1) {
      if (r.query(previ[a[i]], i) >= a[i])
        ret--;
    }
    previ[a[i]] = i;
  }
  printf("%d\\n", ret);
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <stdio.h>
using namespace std;
int n, ptr, ret, a[200000], b[200000], previ[200001];
int main() {
  scanf("%d", &n);
  ret = n;
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]), b[i] = a[i];
  sort(b, b + n);
  for (int i = 0; i < n; i++)
    ptr = lower_bound(b, b + n, a[i]) - b, a[i] = ptr + 1;
  for (int i = 1; i <= n; i++)
    previ[i] = -1;
  for (int i = 0; i < n; i++) {
    if (previ[a[i]] != -1) {
      bool flag = false;
      for (int j = i - 1; j >= previ[a[i]]; j--) {
        if (a[j] < a[i]) {
          flag = true;
          break;
        }
      }
      if (!flag)
        ret--;
    }
    previ[a[i]] = i;
  }
  printf("%d\\n", ret);
}
Problem p01659 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stack>
using namespace std;
int n, x[300000];
int main() {
  cin >> n;
  stack<int> S;
  int sum = 0, cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    if (sum < x[i]) {
      S.push(x[i] - sum);
      cnt++;
      sum = x[i];
    } else {
      while (sum > x[i]) {
        sum -= S.top();
        S.pop();
      }
      if (sum < x[i]) {
        S.push(x[i] - sum);
        sum = x[i];
        cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int n, x[300000], y[300000];
int main() {
  cin >> n;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (y[i] == 1) {
      continue;
    }
    sum++;
    for (int j = i; j < n; j++) {
      if (x[i] > x[j]) {
        break;
      }
      if (x[i] == x[j]) {
        y[j] = 1;
      }
      cnt++;
    }
    if (cnt >= 20000000) {
      goto E;
    }
  }
  cout << sum << endl;
  return 0;
E:;
  for (int i = 0; i < n; i++) {
    y[i] = 0;
  }
  for (int i = 0; i < n / 2; i++) {
    swap(x[i], x[n - i - 1]);
  }
  cnt = 0;
  sum = 0;
  for (int i = 0; i < n; i++) {
    if (y[i] == 1) {
      continue;
    }
    sum++;
    for (int j = i; j < n; j++) {
      if (x[i] > x[j]) {
        break;
      }
      if (x[i] == x[j]) {
        y[j] = 1;
      }
      cnt++;
    }
  }
  cout << sum << endl;
  return 0;
}
Problem p01667 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

bool f = 1, e[100][100];
int n;

void dfs(int now, int par, VI &visit) {
  if (visit[now]) {
    if (now == par)
      f = 0;
    return;
  }
  visit[now] = 1;
  REP(i, n) {
    if (e[now][i])
      dfs(i, par, visit);
  }
}

int main() {
  int m;
  cin >> n >> m;
  VVI h(n, VI(m, 1000)), l(n, VI(m));
  REP(i, n) {
    int k;
    cin >> k;
    while (k--) {
      int j, x;
      string s;
      cin >> j >> s >> x;
      if (s == ">=")
        l[i][j - 1] = max(l[i][j - 1], x);
      else
        h[i][j - 1] = min(h[i][j - 1], x);
    }
  }
  REP(i, n) REP(j, m) if (l[i][j] > h[i][j]) f = 0;
  REP(i, n) REP(j, n) {
    bool g = 0;
    REP(k, m) if (l[i][k] > h[j][k]) g = 1;
    e[i][j] = g;
  }

  REP(i, n) {
    VI visit(n);
    dfs(i, i, visit);
  }

  cout << (f ? "Yes" : "No") << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

bool f = 1, e[100][100];
int n;

void dfs(int now, int par, VI visit) {
  if (visit[now]) {
    if (now == par)
      f = 0;
    return;
  }
  visit[now] = 1;
  REP(i, n) {
    if (e[now][i])
      dfs(i, par, visit);
  }
}

int main() {
  int m;
  cin >> n >> m;
  VVI h(n, VI(m, 1000)), l(n, VI(m));
  REP(i, n) {
    int k;
    cin >> k;
    while (k--) {
      int j, x;
      string s;
      cin >> j >> s >> x;
      if (s == ">=")
        l[i][j - 1] = max(l[i][j - 1], x);
      else
        h[i][j - 1] = min(h[i][j - 1], x);
    }
  }
  REP(i, n) REP(j, m) if (l[i][j] > h[i][j]) f = 0;
  REP(i, n) REP(j, n) {
    bool g = 0;
    REP(k, m) if (l[i][k] > h[j][k]) g = 1;
    e[i][j] = g;
  }

  REP(i, n) {
    VI visit(n);
    dfs(i, i, visit);
  }

  cout << (f ? "Yes" : "No") << endl;

  return 0;
}
Problem p01667 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <stdio.h>

using namespace std;
char str[10];
pair<int, int> v[110][110];
int g[110][110];
int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  for (int i = 0; i < a; i++) {
    int c;
    scanf("%d", &c);
    for (int j = 0; j < b; j++)
      v[i][j] = make_pair(0, 100);
    for (int j = 0; j < c; j++) {
      int d, e;
      scanf("%d%s%d", &d, str, &e);
      d--;
      if (str[0] == '>') {
        v[i][d].first = max(v[i][d].first, e);
      } else
        v[i][d].second = min(v[i][d].second, e);
    }
  }
  bool ok = true;
  for (int i = 0; i < a; i++)
    for (int j = 0; j < b; j++)
      if (v[i][j].first > v[i][j].second)
        ok = false;
  for (int i = 0; i < a; i++)
    for (int j = 0; j < a; j++) {
      for (int k = 0; k < b; k++)
        if (v[i][k].second < v[j][k].first)
          g[i][j] = 1;
    }
  for (int k = 0; k < a; k++)
    for (int i = 0; i < a; i++)
      for (int j = 0; j < a; j++)
        g[i][j] |= (g[i][k] & g[k][j]);
  for (int i = 0; i < a; i++)
    if (g[i][i])
      ok = false;
  for (int i = 0; ok && i < a; i++) {
    for (int j = 0; ok && j < a; j++) {
      for (int k = 0; ok && k < b; k++) {
        for (int l = 0; ok && l < b; l++) {
          if (v[i][k].second < v[j][k].first && v[j][l].second < v[i][l].first)
            ok = false;
          if (v[j][k].second < v[i][k].first && v[i][l].second < v[j][l].first)
            ok = false;
        }
      }
    }
  }
  if (ok)
    printf("Yes\\n");
  else
    printf("No\\n");
}

Error: 0

Fixed submission:

#include <algorithm>
#include <stdio.h>

using namespace std;
char str[3];
pair<int, int> v[100][100];
int g[100][100];
int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  for (int i = 0; i < a; i++) {
    int c;
    scanf("%d", &c);
    for (int j = 0; j < b; j++)
      v[i][j] = make_pair(0, 100);
    for (int j = 0; j < c; j++) {
      int d, e;
      scanf("%d%s%d", &d, str, &e);
      d--;
      if (str[0] == '>') {
        v[i][d].first = max(v[i][d].first, e);
      } else
        v[i][d].second = min(v[i][d].second, e);
    }
  }
  bool ok = true;
  for (int i = 0; i < a; i++)
    for (int j = 0; j < b; j++)
      if (v[i][j].first > v[i][j].second)
        ok = false;
  for (int i = 0; i < a; i++)
    for (int j = 0; j < a; j++) {
      for (int k = 0; k < b; k++)
        if (v[i][k].second < v[j][k].first)
          g[i][j] = 1;
    }
  for (int k = 0; k < a; k++)
    for (int i = 0; i < a; i++)
      for (int j = 0; j < a; j++)
        g[i][j] |= (g[i][k] & g[k][j]);
  for (int i = 0; i < a; i++)
    if (g[i][i])
      ok = false;
  for (int i = 0; ok && i < a; i++) {
    for (int j = 0; ok && j < a; j++) {
      for (int k = 0; ok && k < b; k++) {
        for (int l = 0; ok && l < b; l++) {
          if (v[i][k].second < v[j][k].first && v[j][l].second < v[i][l].first)
            ok = false;
          if (v[j][k].second < v[i][k].first && v[i][l].second < v[j][l].first)
            ok = false;
        }
      }
    }
  }
  if (ok)
    printf("Yes\\n");
  else
    printf("No\\n");
}