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

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fi first
#define se second
#define endl '\\n'
#define mx 1e18
#define mod 998244353
#define lb(v, x) lower_bound(v.begin(), v.end(), x)
#define ub(v, x) upper_bound(v.begin(), v.end(), x)
#define pb push_back
#define io                                                                     \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
ll bino() {
  vector<ll> inv(200005);
  vector<ll> fact(200005);
  vector<ll> inversef(200005);
  inv[0] = 1;
  inv[1] = 1;
  for (int i = 2; i < 200005; ++i)
    inv[i] = (inv[mod % i] * (mod - mod / i)) % mod;

  fact[0] = 1;
  for (int i = 1; i < 200005; i++)
    fact[i] = (i * fact[i - 1]) % mod;

  inversef[0] = 1;
  inversef[1] = 1;
  for (int i = 2; i < 200005; i++)
    inversef[i] = (inversef[i - 1] * inv[i]) % mod;
}
ll powe(ll x, ll n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0) // n is even
    return powe(((x % mod) * (x % mod)) % mod, n / 2);
  else // n is odd
    return (
        (x % mod * (powe(((x % mod) * (x % mod)) % mod, (n - 1) / 2)) % mod) %
        mod);
}
int main() {
  io int n, m;
  cin >> n >> m;
  vector<int> h(n + 1);

  vector<vector<int>> v(n + 1);
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  int x, y;
  int pp = 0;
  while (m--) {
    cin >> x >> y;
    v[x].pb(y);
    v[y].pb(x);
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    if (v[i].size() == 0) {
      ans++;
    } else {
      pp = 0;
      for (int j = 0; j < v[i].size(); j++) {
        if (h[v[i][j]] >= h[i]) {
          pp = 1;
          break;
        }
      }
      if (pp == 0)
        ans++;
    }
  }
  cout << ans << endl;
  // for(int i=1;i<=n;i++)cout<<v[i].size()<<" ";
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fi first
#define se second
#define endl '\\n'
#define mx 1e18
#define mod 998244353
#define lb(v, x) lower_bound(v.begin(), v.end(), x)
#define ub(v, x) upper_bound(v.begin(), v.end(), x)
#define pb push_back
#define io                                                                     \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
ll bino() {
  vector<ll> inv(200005);
  vector<ll> fact(200005);
  vector<ll> inversef(200005);
  inv[0] = 1;
  inv[1] = 1;
  for (int i = 2; i < 200005; ++i)
    inv[i] = (inv[mod % i] * (mod - mod / i)) % mod;

  fact[0] = 1;
  for (int i = 1; i < 200005; i++)
    fact[i] = (i * fact[i - 1]) % mod;

  inversef[0] = 1;
  inversef[1] = 1;
  for (int i = 2; i < 200005; i++)
    inversef[i] = (inversef[i - 1] * inv[i]) % mod;
}
ll powe(ll x, ll n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0) // n is even
    return powe(((x % mod) * (x % mod)) % mod, n / 2);
  else // n is odd
    return (
        (x % mod * (powe(((x % mod) * (x % mod)) % mod, (n - 1) / 2)) % mod) %
        mod);
}
int main() {
  io int n, m;
  cin >> n >> m;
  vector<int> h(n + 1);
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  vector<vector<int>> v(n + 1);
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  int x, y;
  int pp = 0;
  while (m--) {
    cin >> x >> y;
    v[x].pb(y);
    v[y].pb(x);
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    if (v[i].size() == 0) {
      ans++;
    } else {
      pp = 0;
      for (int j = 0; j < v[i].size(); j++) {
        if (h[v[i][j]] >= h[i]) {
          pp = 1;
          break;
        }
      }
      if (pp == 0)
        ans++;
    }
  }
  cout << ans << endl;
}