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;
  cin >> n >> m;

  vector<bool> goods(n, true);

  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }

  vector<int> from(m);
  vector<int> to(m);
  for (int i = 0; i < m; i++) {
    int left, right;
    cin >> left >> right;

    if (h[left - 1] < h[right - 1]) {
      goods[left - 1] = false;
    }
    if (h[left - 1] == h[right - 1]) {
      goods[left - 1] = false;
      goods[right - 1] = false;
    }
    if (h[left - 1] > h[right - 1]) {
      goods[right - 1] = false;
    }
  }

  int num = 0;
  for (int i = 0; i < n; i++) {
    if (goods[i] == true) {
      num++;
    }
  }
  cout << num << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;

  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }

  vector<int> from(m);
  vector<int> to(m);
  for (int i = 0; i < m; i++) {
    int left, right;
    cin >> left >> right;
    from[i] = left - 1;
    to[i] = right - 1;
  }

  vector<int> v(n, 0);
  for (int i = 0; i < n; i++) {
    bool countup = true;
    for (int j = 0; j < m; j++) {
      if (i == from[j] && h[from[j]] <= h[to[j]]) {
        countup = false;
      }
      if (i == to[j] && h[to[j]] <= h[from[j]]) {
        countup = false;
      }
    }
    if (countup == true) {
      v[i]++;
    }
  }
  int num = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] > 0) {
      num++;
    }
  }
  cout << num << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  int ans = 0;

  int N, M;
  cin >> N >> M;

  vector<ll> H(N);
  rep(i, N) { cin >> H[i]; }

  vector<int> good(N, 1);

  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (H[a] > H[b]) {
      good[b] = 0;
    } else if (H[a] < H[b]) {
      good[a] = 0;
    } else {
      good[a] = 0;
      good[b] = 0;
    }
  }

  rep(i, N) { ans += good[i]; }

  cout << ans << endl;

  return 0;
}

Error: WA

Fixed submission:

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

int main() {

  int ans = 0;

  int N, M;
  cin >> N >> M;

  vector<ll> H(N);
  rep(i, N) { cin >> H[i]; }

  vector<int> good(N, 1);

  rep(i, M) {
    int a, b;
    cin >> a >> b;
    good[min(H[a], H[b])] = 0;
  }

  rep(i, N) { ans += good[i]; }

  cout << ans << endl;

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

#include <bits/stdc++.h>
#define INF 2e9
using namespace std;

int main() {
  int N, M, A, B;
  int buf[100001];
  int check[100001];

  cin >> N >> M;
  int ans = N;

  for (int i = 1; i <= N; i++) {
    cin >> buf[i];
    check[i] = 0;
  }
  for (int i = 0; i < M; i++) {
    cin >> A >> B;
    // cout << i <<  " ";
    if (buf[A] < buf[B]) {
      // cout << "a" << endl;
      if (check[A] == 0) {
        ans--;
        check[A] = 1;
      }
    } else if (buf[A] == buf[B]) {
      // cout << "b" << endl;
      if (check[A] == 0) {
        ans--;
        check[A] = 1;
      }
      if (check[B] == 0) {
        ans--;
        check[B] = 1;
      }
    } else if (buf[A] > buf[B]) {
      // cout << "c" << endl;
      if (check[B] == 0) {
        ans--;
        check[B] = 1;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define INF 2e9
using namespace std;

int main() {
  int N, M, A, B;
  int buf[10001];
  int check[10001];

  cin >> N >> M;
  int ans = N;

  for (int i = 1; i <= N; i++) {
    cin >> buf[i];
    check[i] = 0;
  }
  for (int i = 0; i < M; i++) {
    cin >> A >> B;
    // cout << i <<  " ";
    if (buf[A] < buf[B]) {
      // cout << "a" << endl;
      if (check[A] == 0) {
        ans--;
        check[A] = 1;
      }
    } else if (buf[A] == buf[B]) {
      // cout << "b" << endl;
      if (check[A] == 0) {
        ans--;
        check[A] = 1;
      }
      if (check[B] == 0) {
        ans--;
        check[B] = 1;
      }
    } else if (buf[A] > buf[B]) {
      // cout << "c" << endl;
      if (check[B] == 0) {
        ans--;
        check[B] = 1;
      }
    }
  }

  cout << ans << 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;

  vector<int> h(n + 10);

  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }
  vector<bool> cnt(n + 10, 1);
  for (int i = 1; i <= m; i++) {
    int v1, v2;
    cin >> v1 >> v2;
    if (h[v1] <= h[v2]) {
      cnt[v1] = 0;
    }
    if (h[v2] <= h[v1]) {
      cnt[v2] = 0;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    /*if(cnt[i]){
        cout << i << " ";
    }*/
    ans += cnt[i];
  }
  cout << ans;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;

  vector<vector<int>> g(n + 5, vector<int>(m + 5));
  vector<int> h(n + 5);

  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }
  for (int i = 1; i <= m; i++) {
    int v1, v2;
    cin >> v1 >> v2;
    g[v1].push_back(v2);
    g[v2].push_back(v1);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int f = 1;
    for (int j = 0; j < g[i].size(); j++) {
      if (h[g[i][j]] >= h[i]) {
        // cout << i << " " << g[i][j] << "\\n";
        f = 0;
        break;
      }
    }
    ans += f;
  }
  cout << ans;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
  int n, m, A, B;
  scanf("%d %d", &n, &m);
  vector<int> height(n);
  vector<bool> ok(n, true);
  rep(i, n) scanf("%d", &height[i]);

  rep(i, m) {
    scanf("%d %d", &A, &B);
    A--;
    B--;
    if (height[A] <= height[B])
      ok[A] = false;
    if (height[B] <= height[A])
      ok[B] = false;
  }

  A = 0;
  rep(i, n) if (ok[i]) A++;

  printf("%d\\n", A);
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
  int n, m, A, B;
  scanf("%d %d", &n, &m);
  vector<int> height(n);
  vector<vector<int>> road(n, vector<int>(n, -1));
  rep(i, n) scanf("%d", &height[i]);

  rep(i, m) {
    scanf("%d %d", &A, &B);
    A--;
    B--;
    road[A][B] = B;
    road[B][A] = A;
  }

  B = 0;
  rep(i, n) {
    bool flg = true;
    A = height[i];
    rep(j, n) {
      if (road[i][j] > 0) {
        if (height[road[i][j]] >= A) {
          flg = false;
          break;
        }
      }
    }
    if (flg) {
      B++;
    }
  }

  printf("%d\\n", B);
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// int ± 3.27 × 10^4
typedef long long int ll; // ± 9.22 × 10^18
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;

void solve(ll N, ll M, vi H, vi A, vi B) {
  vector<bool> good(N, true);
  for (int i = 0; i < M; i++) {
    int a = A[i] - 1;
    int b = B[i] - 1;
    if (H[a] >= H[b])
      good[b] = false;
    if (H[a] <= H[b])
      good[a] = false;
  }
  int ans = 0;
  for (int i = 0; i < N; i++)
    if (good[i])
      ans++;

  cout << ans << endl;
}

int main() {
  ll N;
  scanf("%lld", &N);
  ll M;
  scanf("%lld", &M);
  vi H(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &H[i]);
  }
  vi A(M);
  vi B(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
  }
  solve(N, M, std::move(H), std::move(A), std::move(B));
  return 0;
}


Error: TLE

Fixed submission:

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

// int ± 3.27 × 10^4
typedef long long int ll; // ± 9.22 × 10^18
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;

void solve(ll N, ll M, vi H, vi A, vi B) {
  vvb T = vvb(N, vb(N, false));
  for (int i = 0; i < M; i++) {
    T[A[i] - 1][B[i] - 1] = true;
    T[B[i] - 1][A[i] - 1] = true;
  }

  vi neverVisit(0);
  for (int i = 0; i < N; i++) {
    neverVisit.push_back(i);
  }

  ll ans = 0;
  while (neverVisit.size() > 0) {
    ll a = neverVisit.back();
    neverVisit.pop_back();
    ll h = H[a];
    bool good = true;
    for (int j = neverVisit.size() - 1; j >= 0; j--) {
      int b = neverVisit[j];
      if (!T[a][b])
        continue;
      if (H[b] <= h) {
        neverVisit.erase(neverVisit.begin() + j);
      }
      if (H[b] >= h) {
        good = false;
        break;
      }
    }
    if (good) {
      ans++;
    }
  }

  cout << ans << endl;
}

int main() {
  ll N;
  scanf("%lld", &N);
  ll M;
  scanf("%lld", &M);
  vi H(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &H[i]);
  }
  vi A(M);
  vi B(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
  }
  solve(N, M, std::move(H), std::move(A), std::move(B));
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#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)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
using Graph = vector<vector<int>>;
using edge = struct {
  int to;
  ll cost;
};
template <class t, class u> void chmax(t &a, u b) {
  if (a < b)
    a = b;
}
template <class t, class u> void chmin(t &a, u b) {
  if (b < a)
    a = b;
}
typedef priority_queue<ll> PQ_HIGH;
typedef priority_queue<ll, VL, greater<ll>> PQ_LOW; // 昇順

int main() {
  int N, M;
  cin >> N >> M;
  VL H(N, 0);
  VI a(M, 0), b(M, 0);
  REP(i, N) { cin >> H[i]; }
  REP(i, M) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
  }
  VI ans(N, 0);
  for (int i = 0; i < M; i++) {
    if (H[a[i]] >= H[b[i]]) {
      ans[b[i]] = 1;
    }
    if (H[a[i]] <= H[b[i]]) {
      ans[a[i]] = 1;
    }
  }
  int count = 0;
  REP(i, N) {
    if (ans[i] == 0) {
      count++;
    }
  }
  cout << count << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#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)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
using Graph = vector<vector<int>>;
using edge = struct {
  int to;
  ll cost;
};
template <class t, class u> void chmax(t &a, u b) {
  if (a < b)
    a = b;
}
template <class t, class u> void chmin(t &a, u b) {
  if (b < a)
    a = b;
}
typedef priority_queue<ll> PQ_HIGH;
typedef priority_queue<ll, VL, greater<ll>> PQ_LOW; // 昇順

int main() {
  int N, M;
  cin >> N >> M;
  VL H(N, 0);
  VI a(N, 0), b(N, 0);
  REP(i, N) { cin >> H[i]; }
  REP(i, M) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
  }
  VI ans(N, 0);
  for (int i = 0; i < M; i++) {
    if (H[a[i]] >= H[b[i]]) {
      ans[b[i]] = 1;
    }
    if (H[a[i]] <= H[b[i]]) {
      ans[a[i]] = 1;
    }
  }
  int count = 0;
  REP(i, N) {
    if (ans[i] == 0) {
      count++;
    }
  }
  cout << count << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm> //sort(a.begin(), a.end());reverse(a.begin(), a.end());
#include <bits/stdc++.h>
#include <iostream>
#include <math.h> //pow(x,y)=x^y 99999とかの場合+1するif文
#define rep(init, i, n) for (int i = init; i < (n); i++)
#define ll long long
#define rev(s) reverse(s.begin(), s.end())
#define sor(v) sort(v.begin(), v.end())
#define PI 3.14159265358979323846264338327950
// コード自動整形 Shift + Option + F @vscode
using namespace std;

/////main/////
int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> H(N), A(M), B(M), goodlocation(N, 1);
  ll sum = 0;

  rep(0, i, N) { cin >> H.at(i); }

  rep(0, i, M) { cin >> A.at(i) >> B.at(i); }

  rep(0, i, M) {
    ll a = A.at(i);
    a = a - 1;
    ll b = B.at(i);
    b = b - 1;
    ;
    if (H.at(a) >= H.at(b)) {
      goodlocation.at(b) = 0;
    }
    if (H.at(b) >= H.at(a)) {
      goodlocation.at(a) = 0;
    }
  }
  // rep(0,i,M){
  //     cout<< "A("<< i+1<<")=" << A.at(i)<<"B("<< i+1<<")=" << B.at(i)<<endl;
  // }
  rep(0, i, N) { sum += goodlocation.at(i); }
  cout << sum << endl;
}
/////main/////

/////function/////

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 <algorithm> //sort(a.begin(), a.end());reverse(a.begin(), a.end());
#include <bits/stdc++.h>
#include <iostream>
#include <math.h> //pow(x,y)=x^y 99999とかの場合+1するif文
#define rep(init, i, n) for (int i = init; i < (n); i++)
#define ll long long
#define rev(s) reverse(s.begin(), s.end())
#define sor(v) sort(v.begin(), v.end())
#define PI 3.14159265358979323846264338327950L
// コード自動整形 Shift + Option + F @vscode
using namespace std;

/////main/////
int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> H(N), A(M), B(M), goodlocation(N, 1);
  ll sum = 0;

  rep(0, i, N) { cin >> H.at(i); }

  rep(0, i, M) { cin >> A.at(i) >> B.at(i); }

  rep(0, i, M) {
    ll a = A.at(i);
    ll b = B.at(i);
    if (H.at(a) >= H.at(b)) {
      goodlocation.at(b) = 0;
    }
    if (H.at(b) >= H.at(a)) {
      goodlocation.at(a) = 0;
    }
  }

  rep(0, i, N) { sum += goodlocation.at(i); }
  cout << sum << endl;
}
/////main/////

/////function/////
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int n, m, h[100005], ans, s[100005];
int main() {
  cin >> n >> m;
  ans = n;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    if (h[a] <= h[b]) {
      if (s[a] == 0) {
        s[a] = 1;
        ans--;
      }
    }
    if (h[b] <= h[a]) {
      if (s[b] == 0) {
        s[b] = 1;
        ans--;
      }
    }
  }
  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int n, m, h[100005], a[100005], b[100005], ans;
bool s[100005];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 1; i <= n; i++) {
    bool bl = 1;
    if (s[i] == 0) {
      for (int j = 1; j <= m; j++) {
        if (a[j] == i) {
          if (h[b[j]] >= h[i]) {
            bl = 0;
            break;
          } else
            s[b[j]] = 1;
        }
        if (b[j] == i) {
          if (h[a[j]] >= h[i]) {
            bl = 0;
            break;
          } else
            s[a[j]] = 1;
        }
      }
      if (bl)
        ans++;
    }
  }
  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<int> h(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> h[i];
  }
  vector<int> g[n + 1];
  for (int i = 1; i <= m; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(h[v]);
    g[v].push_back(h[u]);
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    if (g[i].size() == 0) {
      ++cnt;
      continue;
    }
    if (h[i] > *max_element(g[i].begin(), g[i].end())) {
      ++cnt;
    }
  }
  cout << cnt;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> h[i];
  }
  vector<int> g[n + 1];
  for (int i = 1; i <= m; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    if (h[i] > *max_element(g[i].begin(), g[i].end())) {
      ++cnt;
    }
  }
  cout << cnt;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define maxn 100010
typedef long long ll;
typedef long double ld;
const int MINI INT_MIN;
const ll MINL LLONG_MIN;
int n, m, a, b, g, hello;
int h[maxn], ans = 0, dd[maxn];
vector<int> ct[maxn];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    ct[a].push_back(b);
    ct[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    int l = ct[i].size();
    if (l == 0)
      ans++;
    else {
      bool ck = true;
      for (int j = 0; j < l; j++) {
        if (h[ct[i][j]] < h[i]) {
          a = hello;
        } else {
          ck = false;
          break;
        }
      }
      if (ck)
        ans++;
    }
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define maxn 100010
typedef long long ll;
typedef long double ld;
const int MINI INT_MIN;
const ll MINL LLONG_MIN;
int n, m, a, b;
int h[maxn], ans = 0, dd[maxn];
vector<int> ct[maxn];
int main() {
  ios_base::sync_with_stdio(0);
  memset(dd, 0, sizeof(dd));
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    ct[a].push_back(b);
    ct[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    int l = ct[i].size();
    if (l == 0)
      ans++;
    for (int j = 0; j < l; j++) {
      if (h[ct[i][j]] < h[i] && dd[h[i]] == 0) {
        ans++;
        dd[h[i]]++;
      }
    }
  }
  cout << ans << 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;
typedef long long ll;
int main() {
  ll N, M, A, B;
  cin >> N >> M;
  vector<ll> H(N + 1);
  H[0] = -10;

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

  set<ll> a;

  for (int i = 1; i <= M; i++) {
    cin >> A >> B;
    if (H[A] > H[B]) {
      a.insert(B);
    } else if (H[A] < H[B]) {
      a.insert(A);
    } else {
      a.insert(A);
      a.insert(B);
    }
  }

  cout << N - a.size();

  cin >> N;

  return 0;
}

Error: -6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)


Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int main() {
  ll N, M, A, B;
  cin >> N >> M;
  vector<ll> H(N);

  rep(i, N + 1) { cin >> H[i + 1]; }

  set<ll> a;

  for (int i = 1; i <= M; i++) {
    cin >> A >> B;
    if (H[A] > H[B]) {
      a.insert(B);
    } else if (H[A] < H[B]) {
      a.insert(A);
    } else {
      a.insert(A);
      a.insert(B);
    }
  }

  cout << N - a.size();

  cin >> N;

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

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

int main() {
  int n, m, cnt = 0;
  cin >> n >> m;
  vector<int> h(n, 0);
  vector<int> top(n, 1);

  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }

  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    if (h[a - 1] < h[b - 1]) {
      top[a - 1] = 0;
    } else if (h[a - 1] > h[b - 1]) {
      top[b - 1] = 0;
    } else if (h[a - 1] == h[b - 1]) {
      top[a - 1] = 0;
      top[b - 1] = 0;
    }
  }

  for (auto &t : top) {
    if (t == 1)
      cnt++;
  }
  cout << cnt << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int n, m, cnt = 0;
  cin >> n >> m;
  vector<int> h(n, 0);
  vector<vector<int>> ab(n, vector<int>(n, 0));

  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }

  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    ab[a - 1][b - 1] = 1;
    ab[b - 1][a - 1] = 1;
  }

  int top;
  for (int i = 0; i < n; i++) {
    top = i;
    for (int j = 0; j < n; j++) {
      if (ab[i][j] == 1) {
        if (h[i] <= h[j])
          top = j;
      }
    }
    if (top == i)
      cnt++;
  }
  cout << cnt << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstdlib>
#include <cstring>

char s[8192];
int H[100000];
struct Path {
  int A;
  int B;
} path[100000];
int r[100000];

int main() {
  int N;
  int M;

  fgets(s, sizeof(s), stdin);
  sscanf(s, " %d %d", &N, &M);
  for (int i = 0; i < N; ++i) {
    scanf(" %d", &H[i]);
  }
  fgets(s, sizeof(s), stdin);
  for (int i = 0; i < M; ++i) {
    fgets(s, sizeof(s), stdin);
    sscanf(s, " %d %d", &path[i].A, &path[i].B);
  }

  for (int i = 0; i < M; ++i) {
    if (H[path[i].A - 1] <= H[path[i].B - 1]) {
      r[path[i].A - 1] = 1;
    }
    if (H[path[i].A - 1] >= H[path[i].B - 1]) {
      r[path[i].B - 1] = 1;
    }
  }

  int result = 0;
  for (int i = 0; i < N; ++i) {
    result += (1 - r[i]);
  }

  printf("%d\\n", result);
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <cstdlib>
#include <cstring>

char s[8192];
int H[10000];
struct Path {
  int A;
  int B;
} path[10000];
int r[10000];

int main() {
  int N;
  int M;

  fgets(s, sizeof(s), stdin);
  sscanf(s, " %d %d", &N, &M);
  for (int i = 0; i < N; ++i) {
    scanf(" %d", &H[i]);
  }
  fgets(s, sizeof(s), stdin);
  for (int i = 0; i < M; ++i) {
    fgets(s, sizeof(s), stdin);
    sscanf(s, " %d %d", &path[i].A, &path[i].B);
  }

  for (int i = 0; i < M; ++i) {
    if (H[path[i].A - 1] <= H[path[i].B - 1]) {
      r[path[i].A - 1] = 1;
    }
    if (H[path[i].A - 1] >= H[path[i].B - 1]) {
      r[path[i].B - 1] = 1;
    }
  }

  int result = 0;
  for (int i = 0; i < N; ++i) {
    result += (1 - r[i]);
  }

  printf("%d\\n", result);
  return 0;
}