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

/*

Coded and Decoded by : Yash Kapoor

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

#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll, ll>
#define vl vector<ll>
#define sl set<ll>
#define vll vector<pll>
#define ml map<ll, ll>
#define mll map<pll, ll>
#define all(a) a.begin(), a.end()
#define x first
#define y second
#define sz(x) (ll) x.size()
#define dl '\\n'
#define why (ll)1000000007
// #define why         (ll)998244353
#define lp(i, a, b) for (ll i = a; i < b; ++i)
#define lpr(i, a, b) for (ll i = a; i >= b; i--)
#define lpd(i, x) for (auto i : x)
#define ios                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
ll inf = 1e18;
ld pi = 3.141592653589;
ll mod = why;
ll fast_power(ll base, ll power, ll mod) {
  ll result = 1;
  while (power) {
    if (power % 2)
      result = (result * base) % mod;
    base = (base * base) % mod;
    power /= 2;
  }
  return result;
}

ll inverse(ll base, ll mod) { return fast_power(base, mod - 2, mod); }

ll solve() {
  ll n, m;
  cin >> n >> m;
  vl h(n);
  lp(i, 0, n) cin >> h[i];
  ll ans = 0;
  map<ll, vl> ma;
  lp(i, 0, m) {
    ll x, y;
    cin >> x >> y;
    ma[x].pb(y);
    ma[y].pb(x);
  }
  lpd(x, ma) {
    if (x.y.size() == 0)
      ans++;
    bool f = 0;
    // cout<<x.F<<" ";
    lpd(j, x.y) {
      // cout<<j<<" ";
      if (h[j - 1] >= h[x.x - 1]) {
        f = 1;
        break;
      }
    }
    if (!f) {
      ans++;
    }
  }
  lp(i, 1, n + 1) if (ma[i].size() == 0) ans++;
  cout << ans;
  return 0;
}

int main() {
  ios ll t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}

Error: WA

Fixed submission:

/*

Coded and Decoded by : Yash Kapoor

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

#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll, ll>
#define vl vector<ll>
#define sl set<ll>
#define vll vector<pll>
#define ml map<ll, ll>
#define mll map<pll, ll>
#define all(a) a.begin(), a.end()
#define x first
#define y second
#define sz(x) (ll) x.size()
#define dl '\\n'
#define why (ll)1000000007
// #define why         (ll)998244353
#define lp(i, a, b) for (ll i = a; i < b; ++i)
#define lpr(i, a, b) for (ll i = a; i >= b; i--)
#define lpd(i, x) for (auto i : x)
#define ios                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
ll inf = 1e18;
ld pi = 3.141592653589;
ll mod = why;
ll fast_power(ll base, ll power, ll mod) {
  ll result = 1;
  while (power) {
    if (power % 2)
      result = (result * base) % mod;
    base = (base * base) % mod;
    power /= 2;
  }
  return result;
}

ll inverse(ll base, ll mod) { return fast_power(base, mod - 2, mod); }

ll solve() {
  ll n, m;
  cin >> n >> m;
  vl h(n);
  lp(i, 0, n) cin >> h[i];
  ll ans = 0;
  map<ll, vl> ma;
  lp(i, 0, m) {
    ll x, y;
    cin >> x >> y;
    ma[x].pb(y);
    ma[y].pb(x);
  }
  lpd(x, ma) {
    if (x.y.size() == 0)
      ans++;
    bool f = 0;
    // cout<<x.F<<" ";
    lpd(j, x.y) {
      // cout<<j<<" ";
      if (h[j - 1] >= h[x.x - 1]) {
        f = 1;
        break;
      }
    }
    if (!f) {
      ans++;
    }
  }
  lp(i, 1, n + 1) if (ma[i].size() == 0) ans++;
  cout << ans;
}

int main() {
  ios ll t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}