alexjercan/bugnet huggingface dataset:
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#include <limits.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;

vector<int> p[100001];

int main() {

  lll ii, jj, kk;
  vector<int> ret;
  int n, m;
  vector<int> h;

  cin >> n >> m;

  h.resize(n);

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

  int p1, p2;

  for (ii = 0; ii < m; ii++) {
    cin >> p1 >> p2;

    p[p1 - 1].push_back(p2 - 1);
    p[p2 - 1].push_back(p1 - 1);
  }

  int cnt = 0;
  int myH;

  bool flg;

  for (ii = 0; ii < n; ii++) {
    myH = h[ii];
    flg = true;

    if (p[ii].size() == 0) {

    }

    else {
      for (jj = 0; jj < p[ii].size(); jj++) {
        if (h[p[ii][jj]] >= myH) {
          flg = false;
          break;
        }
      }
    }

    if (flg) {
      cnt++;
    }
  }

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


Error: 0

Fixed submission:

#include <algorithm>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#include <limits.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;

vector<int> p[100001];

int main() {

  lll ii, jj, kk;
  vector<int> ret;
  int n, m;
  vector<int> h;

  cin >> n >> m;

  h.resize(m);

  for (ii = 0; ii < m; ii++) {
    cin >> h[ii];
  }

  int p1, p2;

  for (ii = 0; ii < m; ii++) {
    cin >> p1 >> p2;
    p[p1 - 1].push_back(p2 - 1);
    p[p2 - 1].push_back(p1 - 1);
  }

  int cnt = 0;
  int myH;

  bool flg;
  for (ii = 0; ii < n; ii++) {
    myH = h[ii];
    flg = true;

    if (p[ii].size() == 0) {

    }

    else {
      for (jj = 0; jj < p[ii].size(); jj++) {
        if (h[p[ii][jj]] >= myH) {
          flg = false;
          break;
        }
      }
    }

    if (flg) {
      cnt++;
    }
  }

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define f(i, a, b) for (int i = a; i <= b; i++)
inline ll read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
#define d read()
bool good[100010];
ll n, m, ans;
ll h[100010];
int main() {
  n = d, m = d;
  f(i, 1, n) h[i] = d;
  f(i, 1, m) {
    ll x = d, y = d;
    if (h[x] >= h[y])
      good[y] = 1;
    if (h[x] <= h[y])
      good[x] = 1;
  }
  f(i, 1, n) ans += !good[i];
  cout << ans;
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define f(i, a, b) for (int i = a; i <= b; i++)
inline ll read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
#define d read()
vector<int> e[10010];
ll n, m, ans;
ll h[10010];
int main() {
  n = d, m = d;
  f(i, 1, n) h[i] = d;
  f(i, 1, m) {
    ll x = d, y = d;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  f(i, 1, n) {
    bool fl = 0;
    for (int j = 0; j < e[i].size(); j++)
      if (h[i] <= h[e[i][j]]) {
        fl = 1;
        break;
      }
    ans += !fl;
  }
  cout << ans;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

Error: TLE

Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> h(n, vector<int>(2, 0));
  rep(i, n) cin >> h[i][0];
  vector<vector<int>> ab(m, vector<int>(2));
  rep(i, m) {
    cin >> ab[i][0] >> ab[i][1];
    ab[i][0]--;
    ab[i][1]--;
  }
  rep(i, n) {

    rep(j, m) {
      if (h[i][1] != 0)
        break;
      if (ab[j][0] == i && h[i][0] <= h[ab[j][1]][0])
        h[i][1]++;
      if (ab[j][1] == i && h[i][0] <= h[ab[j][0]][0])
        h[i][1]++;
    }
  }
  int ans = 0;
  rep(i, n) {
    if (h[i][1] == 0)
      ans++;
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ld long double
#define INF 0x3f3f3f3f
const int N = 2e5 + 5;
const ll mod = 1e9 + 7;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  int h[n + 1];
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  vector<int> adj[n + 1];
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int res = 0;
  for (int i = 1; i <= n; i++) {
    if (adj[i].size() == 0)
      res++;
    else {
      bool good = true;
      for (auto next : adj[i]) {
        if (h[i] <= h[next]) {
          good = false;
          break;
        }
      }
      if (good)
        res++;
    }
  }
  cout << res << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ld long double
#define INF 0x3f3f3f3f
const int N = 2e5 + 5;
const ll mod = 1e9 + 7;

int n, m;
int val[N];
bool vis[N];
vector<int> grid[N];
int res = 0;

void dfs(int c, int p) {
  bool good = true;
  for (auto next : grid[c]) {
    if (val[c] <= val[next])
      good = false;
    if (next != p) {
      dfs(next, c);
    }
  }
  if (good)
    res++;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> val[i];
    vis[i] = false;
  }
  int u, v;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    grid[u].push_back(v);
    grid[v].push_back(u);
    vis[u] = true;
    vis[v] = true;
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++) {
    if (!vis[i])
      res++;
  }
  cout << res << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> H(N);
  vector<vector<long long>> A(N);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    A.at(a).push_back(b);
    A.at(b).push_back(a);
  }

  int cnt = 0;
  for (int i = 0; i < N; i++) {
    bool ju = true;
    for (int j = 0; j < A.at(i).size(); j++) {
      if (H.at(i) <= H.at(A.at(i).at(j))) {
        ju = false;
      }
    }
    if (ju) {
      cnt++;
    }
  }

  cout << cnt;
}

Error: -6
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()


Fixed submission:

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

int main() {
  long long N, M;
  vector<long long> H(N);
  vector<vector<long long>> A(N);

  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    A.at(a).push_back(b);
    A.at(b).push_back(a);
  }

  int cnt = 0;
  for (int i = 0; i < N; i++) {
    bool ju = true;
    for (int j = 0; j < A.at(i).size(); j++) {
      if (H.at(i) <= H.at(A.at(i).at(j))) {
        ju = false;
      }
    }
    if (ju) {
      cnt++;
    }
  }

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

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

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int, int>
#define vi vector<int>
#define vpi vector<pi>
#define IOS ios_base::sync_with_stdio(false), cin.tie(NULL)
const int N = 100002, M = 11;
int a[N], h[N];
vi v[N];
int main() {
  int n, m, x, y;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  while (m--) {
    cin >> x >> y;
    if (h[x] <= h[y])
      a[x] = 1;
    if (h[y] <= h[x])
      a[y] = 1;
  }
  int r = 0;
  for (int i = 1; i <= n; i++)
    r += (a[i] == 0);
  cout << r;
  return 0;
}

Error: WA

Fixed submission:

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

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int, int>
#define vi vector<int>
#define vpi vector<pi>
#define IOS ios_base::sync_with_stdio(false), cin.tie(NULL)
const int N = 102, M = 11;
int a[N], h[N];
vi v[N];
int main() {
  int n, m, x, y;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  while (m--) {
    cin >> x >> y;
    if (h[x] <= h[y])
      a[x] = 1;
    if (h[y] <= h[x])
      a[y] = 1;
  }
  int r = 0;
  for (int i = 1; i <= n; i++)
    r += (a[i] == 0);
  cout << r;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

int main() {
  long long n, m;

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

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

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

int main() {
  long long n, m;

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

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

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

#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <tuple>
#include <vector>
#define ll long long
#define MOD = 1e9 + 7

using namespace std;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<int> H(N + 1);
  for (int i = 1; i < N + 1; i++) {
    cin >> H[i];
  }
  map<int, int> ans;
  map<int, int> cnt;
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    cnt[A]++;
    cnt[B]++;
    if ((H[A] - H[B]) > 0) {
      ans[A]++;
    } else if (H[B] - H[A] > 0) {
      ans[B]++;
    }
  }

  int num = 0;
  for (int i = 1; i < N + 1; i++) {
    if (cnt[i] == ans[i])
      num++;
  }
  cout << num << endl;
}

Error: -11

Fixed submission:

#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#define ll long long
#define MOD = 1e9 + 7

using namespace std;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<int> H(N + 1);
  for (int i = 1; i < N + 1; i++) {
    cin >> H[i];
  }

  vector<vector<int>> ans(N + 1);
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    ans[A].push_back(B);
    ans[B].push_back(A);
  }

  vector<bool> chk(N + 1, false);
  for (int i = 1; i < ans.size() + 1; i++) {
    int num = 0;
    for (int j = 0; j < ans[i].size(); j++) {
      if (H[i] - H[ans[i][j]] > 0) {
        num++;
      }
    }
    if (num == ans[i].size())
      chk[i] = true;
  }

  int cnt = 0;
  for (int i = 1; i < chk.size() + 1; i++) {
    if (chk[i])
      cnt++;
  }

  cout << cnt - 1 << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define pb push_back
#define ll long long

using namespace std;

const int N = 1e5 + 5;
vector<int> gr[N];
ll d[N], used[N];
int cnt = 0;

void dfs(int v) {
  used[v] = 1;
  int fl = 1;
  for (auto e : gr[v]) {
    if (d[v] <= d[e])
      fl = 0;
  }
  if (fl)
    cnt++;
  for (auto e : gr[v]) {
    if (!used[e])
      dfs(e);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> d[i + 1];
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    gr[u].pb(v);
    gr[v].pb(u);
  }
  for (int i = 1; i <= n; i++) {
    if (!used[i])
      dfs(i);
  }
  cout << cnt;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
#define ll long long

using namespace std;

const int N = 1e5 + 5;
vector<int> gr[N];
ll d[N], used[N];
int cnt = 0;

int dfs(int v) {
  used[v] = 1;
  int fl = 1;
  for (auto e : gr[v]) {
    if (d[v] <= d[e])
      fl = 0;
  }
  if (fl)
    cnt++;
  for (auto e : gr[v]) {
    if (!used[e])
      dfs(e);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> d[i + 1];
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    gr[u].pb(v);
    gr[v].pb(u);
  }
  for (int i = 1; i <= n; i++) {
    if (!used[i])
      dfs(i);
  }
  cout << cnt;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>

using namespace std;
#define N 100010
int main() {
  int n, m, h[N], ma[N];
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
    ma[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    ma[a] = max(ma[a], h[b]);
    ma[b] = max(ma[b], h[a]);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += h[i] > ma[i];
  }
  cout << ans << endl;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define MAX_N 100000
#define MAX_M 100000

int main() {
  int N, M;
  int H[MAX_N];
  int A[MAX_M], B[MAX_M];
  // int d[MAX_N][MAX_M];
  int path[2] = {0, 0};
  int count = 0;

  scanf("%d %d", &N, &M);
  // printf("N = %d M = %d\\n", N, M);

  int d[N][M];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      d[i][j] = -1;
    }
  }

  for (int i = 0; i < N; i++) {
    scanf("%d", &H[i]);
    // printf("H[%d] = %d\\n", i, H[i]);
  }

  for (int j = 0; j < M; j++) {
    scanf("%d %d", &A[j], &B[j]);
    path[0] = H[A[j] - 1] - H[B[j] - 1];
    path[1] = H[B[j] - 1] - H[A[j] - 1];
    d[A[j] - 1][B[j] - 1] = path[0];
    d[B[j] - 1][A[j] - 1] = path[1];
    // printf("d[%d][%d] = %d d[%d][%d] = %d\\n", A[j] - 1, B[j] - 1, d[A[j] -
    // 1][B[j] - 1], B[j] - 1, A[j] - 1, d[B[j] - 1][A[j] - 1]);
  }

  /*
      for (int i = 0; i < N; i++) {
          for (int j = 0; j < M; j++) {
              printf("%d", d[i][j]);
          }
          printf("\\n");
      } */

  for (int i = 0; i < N; i++) {
    int fact = 0;
    for (int j = 0; j < M; j++) {
      fact += d[i][j];
      if (d[i][j] > 0 && H[i] > H[j] || fact == -N) {
        count++;
        break;
      }
    }
  }

  printf("%d\\n", N - count);

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

#include <iostream>

using namespace std;

int n, m;
int H[100000];
int d[100000] = {0};

int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    d[i] = 0;
    cin >> H[i];
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;

    d[a] = max(d[a], H[b]);
    d[b] = max(d[b], H[a]);
  }
  int ret = 0;
  for (int i = 1; i <= n; i++) {
    if (H[i] > d[i])
      ret++;
  }
  cout << ret << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

ll N, M;
ll H[10000];
vector<P> path;
int d[10000][10000];

set<int> ans;

void solve() {
  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j < N; j++)
      d[i][j] = 0;
  }

  for (ll i = 0; i < M; i++) {
    int a = path[i].first;
    int b = path[i].second;

    d[a][b] = 1;
    d[b][a] = 1;
  }

  for (int i = 0; i < N; i++) {

    bool ok = true;
    for (int j = 0; j < N; j++) {
      if (d[i][j] == 1 && H[j] >= H[i]) {
        ok = false;
        break;
      }
    }
    if (ok) {

      ans.insert(i);
    }
  }
  cout << ans.size() << endl;
}

int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  for (int i = 0; i < M; i++) {
    P p;
    cin >> p.first >> p.second;
    p.first -= 1;
    p.second -= 1;
    path.push_back(p);
  }

  solve();

  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> h(n);
  vector<int> a(m), b(m);
  for (int i = 0; i < n; i++) {
    cin >> h.at(i);
  }
  for (int i = 0; i < m; i++) {
    cin >> a.at(i) >> b.at(i);
  }
  map<int, vector<int>> mp;
  for (int i = 0; i < m; i++) {
    mp[a.at(i)].push_back(b.at(i));
    mp[b.at(i)].push_back(a.at(i));
  }
  int count = n;
  for (auto iter = mp.begin(); iter != mp.end(); ++iter) {
    vector<int> tmp = iter->second;
    for (int j = 0; j < tmp.size(); j++) {
      if (h.at((iter->first) - 1) <= h.at(tmp.at(j) - 1)) {
        count--;
        break;
      }
    }
  }

  cout << count << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> h(n);
  vector<int> a(m), b(m);
  for (int i = 0; i < n; i++) {
    cin >> h.at(i);
  }
  for (int i = 0; i < m; i++) {
    cin >> a.at(i) >> b.at(i);
  }
  int count = n;
  for (int i = 0; i < n; i++) {
    vector<int> tmp(2 * m);
    int iter = 0;
    for (int j = 0; j < m; j++) {
      if (a.at(j) == i + 1) {
        tmp.at(iter) = b.at(j);
        iter++;
      }
      if (b.at(j) == i + 1) {
        tmp.at(iter) = a.at(j);
        iter++;
      }
    }
    for (int j = 0; j < iter; j++) {
      if (h.at(i) <= h.at(tmp.at(j) - 1)) {
        count--;
        break;
      }
    }
  }
  cout << count << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <memory.h>
#include <vector>

using namespace std;

int N, M;
int H[100001];

int main() {
  int ma[100001];
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    cin >> H[i];
    ma[i] = 0;
  }
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    ma[a] = max(ma[a], H[b]);
    ma[b] = max(ma[b], H[a]);
  }
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    if (H[i] > ma[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <memory.h>
#include <vector>

using namespace std;

int N, M;
int H[100001];
int A[100001], B[100001];

void solve() {
  pair<int, int> X[100001];
  for (int i = 0; i < N; i++) {
    X[i] = make_pair(-H[i], i + 1);
  }
  sort(X, X + N);

  vector<int> E[10000];
  for (int i = 0; i < M; i++) {
    int s = A[i] - 1, e = B[i] - 1;
    E[s].push_back(e);
    E[e].push_back(s);
  }
  // for (int i = 0; i < N; i++) {
  //   cout << "(" << i << ")";
  //   for (int j = 0; j < E[i].size(); j++) {
  //     cout << E[i][j];
  //   }
  //   cout << endl;
  // }

  // for (int i = 0; i < N; i++) {
  //   cout << X[i].second-1 << ": " << (-X[i].first) << endl;
  // }

  bool flag[100001];
  memset(flag, 1, N);

  int ans = 0;
  for (int i = 0; i < N; i++) {
    int s = X[i].second - 1;
    if (flag[s]) {
      bool t = true;
      for (int j = 0; j < E[s].size(); j++) {
        if (H[E[s][j]] >= H[s]) {
          t = false;
          break;
        }
      }
      if (t) {
        // cout << s << " is good" << endl;
        ans++;
      }
      for (int j = 0; j < E[s].size(); j++) {
        flag[E[s][j]] = false;
      }
    }
  }

  cout << ans << endl;
}

int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
  }
  solve();
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<ll> h(N);
  for (ll i = 0; i < N; i++) {
    cin >> h.at(i);
  }
  ll a, b;
  vector<ll> count(N, 0);
  for (ll j = 0; j < M; j++) {
    cin >> a >> b;
    if (h.at(a - 1) < h.at(b - 1)) {
      count.at(a - 1)++;
    } else if (h.at(a - 1) == h.at(b - 1)) {
      count.at(a - 1)++;
      count.at(b - 1)++;
    } else {
      count.at(b - 1)++;
    }
  }
  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    if (count.at(i) == 0) {
      ans++;
    }
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<ll> h(N);
  for (ll i = 0; i < N; i++) {
    cin >> h.at(i);
  }
  ll a, b;
  vector<ll> count(N, 0);
  for (ll j = 0; j < M; j++) {
    cin >> a >> b;
    ll c = min(h.at(a - 1), h.at(b - 1));
    count.at(c)++;
  }
  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    if (count.at(i) == 0) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7, M = 1e5 * 2 + 50;
int n, m;
int hh[N];
int h[M], w[M], e[M], ne[M], idx;
bool st[N];
void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }
int main() {
  cin >> n >> m;
  memset(h, -1, sizeof h);
  for (int i = 1; i <= n; i++)
    cin >> hh[i];
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    add(a, b);
    add(b, a);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int flag = 1;
    for (int j = h[i]; j != -1; j = ne[j]) {
      int k = e[j];
      if (hh[i] <= hh[k]) {
        flag = 0;
        break;
      }
    }
    if (flag)
      ans++;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5, M = 1e5 * 2;
int n, m;
int hh[N];
int h[M], w[M], e[M], ne[M], idx;
bool st[N];
void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }
int main() {
  cin >> n >> m;
  memset(h, -1, sizeof h);
  for (int i = 1; i <= n; i++)
    cin >> hh[i];
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    add(a, b);
    add(b, a);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int flag = 1;
    for (int j = h[i]; j != -1; j = ne[j]) {
      int k = e[j];
      if (hh[i] <= hh[k]) {
        flag = 0;
        break;
      }
    }
    if (flag)
      ans++;
  }
  cout << ans << endl;
}