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

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

int main() {
  int N, M, ans = 0;
  cin >> N >> M;
  vector<long long> H(N + 1);
  vector<bool> check(N + 1);
  vector<int> A(M), B(M);
  for (int i = 1; i <= N; i++) {
    cin >> H.at(i);
    check.at(i) = true;
  }
  for (int i = 0; i < M; i++) {
    cin >> A.at(i) >> B.at(i);
  }
  for (int j = 0; j < M; j++) {
    if (H.at(A.at(j)) == H.at(B.at(j))) {
      check.at(A.at(j)) = false;
      check.at(B.at(j)) = false;
    } else if (H.at(A.at(j)) < H.at(B.at(j))) {
      check.at(A.at(j)) = false;
    } else {
      check.at(B.at(j)) = false;
    }
  }
  for (int i = 1; i <= N; i++) {
    if (check.at(i)) {
      ans++;
    }
  }
  cout << ans;
}

Error: TLE

Fixed submission:

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

int main() {
  int N, M, ans = 0;
  cin >> N >> M;
  vector<long long> H(N + 1);
  vector<bool> check(N + 1);
  vector<int> A(M), B(M);
  for (int i = 1; i <= N; i++) {
    cin >> H.at(i);
    check.at(i) = true;
  }
  for (int i = 0; i < M; i++) {
    cin >> A.at(i) >> B.at(i);
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < M; j++) {
      if (A.at(j) == i) {
        if (H.at(A.at(j)) <= H.at(B.at(j))) {
          check.at(i) = false;
        }
      } else if (B.at(j) == i) {
        if (H.at(A.at(j)) >= H.at(B.at(j))) {
          check.at(i) = false;
        }
      }
    }
    if (check.at(i)) {
      ans++;
    }
  }
  cout << ans;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long long n, m, x;
  x = 0;
  cin >> n >> m;
  vector<long long> h(n);
  vector<long long> a(m);
  vector<long long> b(m);
  vector<long long> sum(n);
  for (int i = 0; i < n; i++) {
    cin >> h.at(i);
  }
  for (long long i = 0; i < m; i++) {
    cin >> a.at(i) >> b.at(i);
  }
  for (long long i = 0; i < m; i++) {
    if (h.at(a.at(i) - 1) <= h.at(b.at(i) - 1)) {
      sum.at(a.at(i) - 1) = 1;
    }
    if (h.at(a.at(i) - 1) >= h.at(b.at(i) - 1)) {
      sum.at(b.at(i) - 1) = 1;
    }
  }
  for (long long i = 0; i < n; i++) {
    if (sum.at(i) == 0) {
      x++;
    }
  }
  cout << x << endl;
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 4) >= this->size() (which is 4)


Fixed submission:

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

int main() {
  long long n, m, x;
  x = 0;
  cin >> n >> m;
  vector<long long> h(n);
  vector<long long> a(m);
  vector<long long> b(m);
  vector<long long> sum(n);
  for (int i = 0; i < n; i++) {
    cin >> h.at(i);
  }
  for (long long i = 0; i < m; i++) {
    cin >> a.at(i) >> b.at(i);
  }
  for (long long i = 0; i < m; i++) {
    if (h.at(a.at(i)) < h.at(b.at(i))) {
      sum.at(a.at(i)) = 1;
    } else if (h.at(a.at(i)) > h.at(b.at(i))) {
      sum.at(b.at(i)) = 1;
    }
  }
  for (long long i = 0; i < n; i++) {
    if (sum.at(i) == 0) {
      x++;
    }
  }
  cout << x << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  int N, M;

  cin >> N >> M;

  vector<int> H(N);
  for (size_t i = 0; i < N; i++) {
    cin >> H[i];
  }

  vector<set<int>> G(N);

  for (size_t i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;

    A--;
    B--;

    G[A].insert(B);
    G[B].insert(A);
  }

  vector<bool> result(N, true);

  for (size_t i = 0; i < N; i++) {
    for (auto temp : G[i]) {
      if (H[i] > H[temp]) {
        result[temp] = false;
      } else if (H[i] < H[temp]) {
        result[i] = false;
      } else {
        result[temp] = false;
        result[i] = false;
      }
    }
  }

  cout << count(result.begin(), result.end(), true) << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

bool dfs(int start, vector<vector<int>> G, vector<int> H) {

  for (auto temp : G[start]) {
    if (H[start] <= H[temp]) {
      return false;
    }
  }
  return true;
}

int main() {

  int N, M;

  cin >> N >> M;

  vector<int> H(N);
  for (size_t i = 0; i < N; i++) {
    cin >> H[i];
  }

  vector<vector<int>> G(N);

  for (size_t i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;

    A--;
    B--;

    G[A].emplace_back(B);
    G[B].emplace_back(A);
  }

  vector<bool> result(N);
  for (size_t i = 0; i < N; i++) {
    result[i] = dfs(i, G, H);
  }

  cout << count(result.begin(), result.end(), true) << endl;

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

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

int main() {
  int N, M;
  cin >> N >> M;
  long long H[N];
  bool good[N];
  vector<vector<int>> v(N, vector<int>(0));
  for (int i = 0; i < N; i++) {
    cin >> H[i];
    good[i] = true;
  }
  int A[M], B[M];
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
    v[A[i] - 1].push_back(B[i] - 1);
    v[B[i] - 1].push_back(A[i] - 1);
  }
  for (int i = 0; i < N; i++) {
    bool is_good = true;
    for (int j : v[i]) {
      if (H[i] <= H[j]) {
        is_good = false;
        break;
      }
    }
    if (is_good == false) {
      good[i] = false;
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (good[i]) {
      ans++;
    }
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

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

int main() {
  int N, M;
  cin >> N >> M;
  long long H[N];
  bool good[N];
  for (int i = 0; i < N; i++) {
    cin >> H[i];
    good[i] = true;
  }
  int A[N], B[N];
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
  }
  for (int i = 0; i < M; i++) {
    if (H[A[i] - 1] > H[B[i] - 1]) {
      good[A[i] - 1] = true;
      good[B[i] - 1] = false;
    } else if (H[A[i] - 1] == H[B[i] - 1]) {
      good[B[i] - 1] = false;
      good[A[i] - 1] = false;
    } else {
      good[A[i] - 1] = false;
      good[B[i] - 1] = true;
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (good[i]) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
int main() {
  ll N, M;
  cin >> N >> M;
  ll H[N];
  ll i;
  for (i = 0; i < N; i++) {
    cin >> H[i];
  }
  vector<ll> p[N];
  ll a, b;
  for (i = 0; i < M; i++) {
    cin >> a >> b;
    p[a - 1].push_back(b - 1);
    p[b - 1].push_back(a - 1);
  }
  ll ans = 0;
  ll t;
  for (i = 0; i < N; i++) {
    t = 1;
    for (auto itr = p[i].begin(); itr != p[i].end(); itr++) {
      if (H[i] <= H[*itr])
        t = 0;
    }
    ans += t;
  }
  cout << ans;
  return 0;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
int main() {
  ll N, M;
  ll H[N];
  ll i;
  cin >> N >> M;
  for (i = 0; i < N; i++) {
    cin >> H[i];
  }
  vector<ll> p[N];
  ll a, b;
  for (i = 0; i < M; i++) {
    cin >> a >> b;
    p[a - 1].push_back(b - 1);
    p[b - 1].push_back(a - 1);
  }
  ll ans = 0;
  ll t;
  for (i = 0; i < N; i++) {
    t = 1;
    for (auto itr = p[i].begin(); itr != p[i].end(); itr++) {
      if (H[i] <= H[*itr])
        t = 0;
    }
    ans += t;
  }
  cout << ans;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<uint64_t> h(n);
  for (auto &it : h) {
    cin >> it;
  }

  set<int> good;
  for (int i = 0; i < n; i++) {
    good.insert(i);
  }

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (h.at(a) == h.at(b)) {
      good.erase(a);
      good.erase(b);
    }
    if (h.at(a) < h.at(b))
      good.erase(a);
    if (h.at(b) < h.at(a))
      good.erase(b);
  }
  cout << good.size() << endl;
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 1361215615) >= this->size() (which is 4)


Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<uint64_t> h(n);
  for (auto &it : h) {
    cin >> it;
  }

  set<int> good;
  for (int i = 0; i < n; i++) {
    good.insert(i);
  }

  for (int i = 0; i < m; i++) {
    int a, b;
    a--;
    b--;
    if (h.at(a) == h.at(b)) {
      good.erase(a);
      good.erase(b);
    }
    if (h.at(a) < h.at(b))
      good.erase(a);
    if (h.at(b) < h.at(a))
      good.erase(b);
  }
  cout << good.size() << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> ok(n, true);
  rep(i, n) { cin >> h.at(i); }
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (h.at(a) <= h.at(b))
      ok[a] = false;
    if (h.at(b) <= h.at(a))
      ok[b] = false;
  }
  int ans = 0;
  rep(i, n) {
    if (ok[i]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 4) >= this->size() (which is 4)


Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> H(n);
  rep(i, n) { cin >> H.at(n); }
  vector<int> Ans(n);
  rep(j, m) {
    int a, b;
    cin >> a >> b;
    if (a > b) {
      Ans.at(b - 1)--;
    } else {
      Ans.at(a - 1)--;
    }
  }
  int R;
  rep(k, n) {
    if (Ans.at(k) == 0) {
      R++;
    }
  }
  cout << R << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> ok(n, true);
  rep(i, n) cin >> h[i];
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (h[a] >= h[b])
      ok[b] = false;
    if (h[b] >= h[a])
      ok[a] = false;
  }
  int ans = 0;
  rep(i, n) if (ok[i]) ans++;
  cout << ans << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> ok(n, true);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (h[a] > h[b])
      ok[b] = false;
    if (h[b] > h[a])
      ok[a] = false;
  }
  int ans = 0;
  rep(i, n) if (ok[i] == true) ans++;
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  // vector<vector<int>> road(n,vector<int>(n,0));
  vector<int> h(n);
  vector<bool> flag(n, true);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  int tmp_a, tmp_b;
  for (int i = 0; i < m; i++) {
    cin >> tmp_a >> tmp_b;
    /*
    road[tmp_a-1][tmp_b-1]=1;
    road[tmp_b-1][tmp_a-1]=1;
    */
    if (h[tmp_a - 1] > h[tmp_b - 1])
      flag[tmp_b - 1] = false;
    if (h[tmp_a - 1] < h[tmp_b - 1])
      flag[tmp_a - 1] = false;
    if (h[tmp_a - 1] == h[tmp_b - 1]) {
      flag[tmp_b - 1] = false;
      flag[tmp_a - 1] = false;
    }
  }
  int ans = 0;
  // bool flag=true;
  for (int i = 0; i < n; i++) {
    if (flag[i]) {
      ans++;
    }
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> road(n, vector<int>(n, 0));
  vector<int> h(n);
  vector<bool> flag(n, true);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  int tmp_a, tmp_b;
  for (int i = 0; i < m; i++) {
    cin >> tmp_a >> tmp_b;
    /*
    road[tmp_a-1][tmp_b-1]=1;
    road[tmp_b-1][tmp_a-1]=1;
    */
    if (h[tmp_a - 1] > h[tmp_b - 1])
      flag[tmp_b - 1] = false;
    if (h[tmp_a - 1] < h[tmp_b - 1])
      flag[tmp_a - 1] = false;
    if (h[tmp_a - 1] == h[tmp_b - 1]) {
      flag[tmp_b - 1] = false;
      flag[tmp_a - 1] = false;
    }
  }
  int ans = 0;
  // bool flag=true;
  for (int i = 0; i < n; i++) {
    if (flag[i]) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int)x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template <class T> void print(const T &t) { cout << t << endl; }
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  ll n, m;
  cin >> n >> m;
  ll ans = 0;
  vi h(n);
  rep(i, n) { cin >> h[i]; }
  vi a(m);
  vi b(m);
  vector<bool> s(n, true);
  rep(i, m) {
    cin >> a[i] >> b[i];
    if (h[a[i] - 1] > h[b[i] - 1]) {
      s[b[i] - 1] = false;
    } else if (h[a[i] - 1] < h[b[i] - 1]) {
      s[a[i] - 1] = false;
    } else {
      s[a[i] - 1] = false;
      s[b[i] - 1] = false;
    }
  }
  rep(i, n) {
    if (s[i] == true) {
      ans++;
    }
  }
  print(ans);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int)x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template <class T> void print(const T &t) { cout << t << endl; }
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  ll n, m;
  cin >> n >> m;
  ll ans = 0;
  vi h(n);
  rep(i, n) { cin >> h[i]; }
  vi a(m);
  vi b(m);
  rep(i, m) { cin >> a[i] >> b[i]; }
  for (ll i = 1; i <= n; i++) {
    bool z = true;
    rep(j, m) {
      if (a[j] == i && h[i - 1] <= h[b[j] - 1]) {
        z = false;
      } else if (b[j] == i && h[i - 1] <= h[a[j] - 1]) {
        z = false;
      }
    }
    if (z) {
      ans++;
    }
  }
  print(ans);
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <iostream>  // cout, endl, cin
#include <math.h>    // sqrt
#include <string>    // string, to_string, stoi
#include <vector>    // vector
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<long long> high(N);
  for (int i = 0; i < N; i++) {
    cin >> high.at(i);
  }
  vector<vector<int>> road(M, vector<int>(2));
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> road.at(i).at(j);
    }
  }
  vector<bool> bit(N, true);
  int ha, hb;
  for (int i = 0; i < M; i++) {
    ha = road.at(i).at(0) - 1;
    hb = road.at(i).at(1) - 1;
    if (high.at(ha) <= high.at(hb)) {
      bit.at(ha) = false;
    }
    if (high.at(hb) <= high.at(ha)) {
      bit.at(hb) = false;
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (bit.at(i)) {
      ans++;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <iostream>  // cout, endl, cin
#include <math.h>    // sqrt
#include <string>    // string, to_string, stoi
#include <vector>    // vector
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<long long> high(N);
  for (int i = 0; i < N; i++) {
    cin >> high.at(i);
  }
  vector<vector<int>> road(M, vector<int>(2));
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> road.at(i).at(j);
    }
  }
  int ans = 0;
  bool check;
  for (int i = 0; i < N; i++) {
    check = true;
    for (int j = 0; j < M; j++) {
      if (road.at(j).at(0) == i + 1 &&
          high.at(i) <= high.at(road.at(j).at(1) - 1)) {
        check = false;
        break;
      }
      if (road.at(j).at(1) == i + 1 &&
          high.at(i) <= high.at(road.at(j).at(0) - 1)) {
        check = false;
        break;
      }
    }
    if (check) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long h[N];
int g[N];
int v[N];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &h[i]);
  }
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    g[a]++;
    g[b]++;
    if (h[a] > h[b])
      v[a]++;
    if (h[b] > h[a])
      v[b]++;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    //		if(g[i]!=0){
    if (g[i] == v[i])
      ans++;
    //		}
  }
  printf("%d\\n", ans);
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 10000 + 5;
int h[N];
int g[N][N];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &h[i]);
  }
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    g[a][b] = g[b][a] = 1;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int num = 0, num1 = 0;
    for (int j = 1; j <= n; j++) {
      if (g[i][j] == 1) {
        num++;
        if (h[i] >= h[j]) {
          num1++;
        }
      }
    }
    if ((num == num1) && num)
      ans++;
  }
  printf("%d\\n", ans);
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int N, M;
vector<int> H;
vector<int> ma;

int main() {
  cin >> N >> M;
  H.resize(N);
  ma.resize(N);

  for (int i = 0; i < N; i++) {
    cin >> H[i];
    ma[i] = 0;
  }
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    ma[a - 1] = max(ma[a - 1], H[b - 1]);
    ma[b - 1] = max(ma[b - 1], H[a - 1]);
  }

  int count = 0;
  for (int i = 0; i < N; i++) {
    count += H[i] > ma[i];
  }
  cout << count << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int N, M;
vector<int> H, A, B;
vector<bool> possible;

bool check(int n) {
  for (int i = 0; i < M; i++) {
    if (A[i] - 1 == n) {
      if (H[n] <= H[B[i] - 1]) {
        possible[n] = false;
        return false;
      } else {
        possible[B[i] - 1] = false;
      }
    } else if (B[i] - 1 == n) {
      if (H[n] <= H[A[i] - 1]) {
        possible[n] = false;
        return false;
      } else {
        possible[A[i] - 1] = false;
      }
    }
  }
  return true;
}
int main() {
  cin >> N >> M;
  H.resize(N);
  A.resize(M);
  B.resize(M);
  possible.resize(N);

  for (int i = 0; i < N; i++) {
    cin >> H[i];
    possible[i] = true;
  }
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
  }

  int count = 0;
  for (int i = 0; i < N; i++) {
    if (possible[i]) {
      if (check(i)) {
        count++;
      }
    }
  }
  cout << count << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

/* In the name of Allah */

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 1000 + 10;
int x[MAXN];
int h[MAXN];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    x[a] = max(x[a], h[b]);
    x[b] = max(x[b], h[a]);
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    if (h[i] > x[i]) {
      sum++;
    }
  }
  cout << sum;
  return 0;
}

Error: 127
/tmp/458dde6d-a451-40a7-bb31-2c4f3ff77ab6.out: error while loading shared libraries: libc.so.6: failed to map segment from shared object


Fixed submission:

/* In the name of Allah */

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10 * 1000 + 10;
bool x[MAXN][MAXN];
int h[MAXN];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    x[a][b] = 1;
    x[b][a] = 1;
  }
  int flag = 1, sum = 0;
  for (int i = 1; i <= n; i++) {
    flag = 1;
    for (int j = 1; j <= n; j++) {
      if (i == j) {
        continue;
      }
      if (x[i][j] == true) {
        if (h[i] <= h[j]) {
          flag = 0;
          break;
        }
      }
    }
    if (flag == 1) {
      sum++;
    }
  }
  cout << sum;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int arr[n], ans = 0;
  vector<int> adjlist[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    adjlist[a - 1].push_back(b - 1);
    adjlist[b - 1].push_back(a - 1);
  }

  for (int i = 0; i < n; i++) {
    bool inter = true;
    // cout<<adjlist[i].size()<<endl;
    for (int j = 0; j < adjlist[i].size(); j++) {
      if (arr[i] <= arr[adjlist[i][j]]) {
        inter = false;
        break;
      }
    }
    if (inter)
      ans++;
  }

  cout << ans;
  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int arr[n], ans = 0;
  vector<int> adjlist[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    adjlist[a].push_back(b);
    adjlist[b].push_back(a);
  }

  for (int i = 0; i < n; i++) {
    bool inter = true;
    for (int j = 0; (unsigned)j < adjlist[i].size(); j++) {
      if (arr[i] <= arr[adjlist[i][j] - 1]) {
        inter = false;
        break;
      }
    }
    if (inter)
      ans++;
  }

  cout << ans;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<int> maxh(n, -1);
  vector<int> tmp(n, -10000000);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    maxh[a] = max(maxh[a], h[b]);
    maxh[b] = max(maxh[b], h[a]);
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (maxh[i] < h[i]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {

  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<int> maxh(m, -1);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    maxh[a] = max(maxh[a], h[b]);
    maxh[b] = max(maxh[b], h[a]);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (maxh[i] < h[i]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}