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

#include <algorithm>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#include <math.h>
#include <numeric>
#include <stdio.h>
// #include "boost/algorithm/string.hpp"
#define fio                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define mod 1000000007
#define mod1 mod
#define mod2 1000000007
#define ll long long int
#define ull unsigned long long int
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#define readi(x) scanf("%d", &x)
#define reads(x) scanf("%s", x)
#define readl(x) scanf("%I64d", &x)
#define rep(i, n) for (i = 0; i < n; i++)
#define revp(i, n) for (i = (n - 1); i >= 0; i--)
#define myrep1(i, a, b) for (i = a; i <= b; i++)
#define myrep2(i, a, b) for (i = b; i >= a; i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define sec second
#define MAXN 1000000000000000005
#define MINN -1000000000000000000
#define INTMAX 1000001000
#define pii pair<ll, ll>
#define pdd pair<double, double>
#define pic pair<int, char>
#define lgn 20
#define ddouble long double
#define minus minu
#define PI 3.1415926535
#define lgn 20
#define coutd(x) cout << fixed << setprecision(x)
#define DECIMAL(n) std::cout << std::fixed << std::setprecision(n);
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define fil(v, x) fill(all(v), x)
#define filcon(v, x) iota(all(v), x)
#define newl '\\n'
#define sz(x) (int)x.size()
ull sqr(int x) { return 1ll * x * x; }

// #define INTMAX 200000000

// using namespace boost;
// #define si short int

using namespace std;
using namespace __gnu_pbds;
typedef priority_queue<ll, vector<ll>> max_pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> min_pq;
ll toint(const string &s) {
  stringstream ss;
  ss << s;
  ll x;
  ss >> x;
  return x;
}
string tostring(ll number) {
  stringstream ss;
  ss << number;
  return ss.str();
}
template <typename T> T toIntegralType(const string &str) {
  static_assert(is_integral<T>::value, "Integral type required.");
  T ret;
  stringstream ss(str);
  ss >> ret;
  if (to_string(ret) != str)
    throw invalid_argument("Can't convert " + str);
  return ret;
}
// using namespace __gnu_pbds;
// typedef priority_queue<pair<ll,char> , vector<pair<ll , char> > > max_pq;
// typedef priority_queue<pii , vector<pii > ,greater<pii > > min_pq;
typedef tree<pii, null_type, less<pii>, rb_tree_tag,
             tree_order_statistics_node_update>
    OST;
// typedef priority_queue<pair < ll , pair < pii , ll > >  , vector<pair < ll ,
// pair < pii , ll > >  > ,greater<pair < ll , pair < pii , ll > >  > > min_pq;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cout << name << " : " << arg1 << std::endl;
  // use cerr if u want to display at the bottom
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
#define nn 2000005
bool isPowerOfTwo(ll n) {
  if (n == 0)
    return false;

  return (ceil(log2(n)) == floor(log2(n)));
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
int psieve[1000005] = {0};
void prime_sieve() {
  // first mark all odd number prime
  for (int i = 3; i <= 1000000; i += 2) {
    psieve[i] = 1;
  }

  // Sieve
  for (ll i = 3; i <= 1000000; i += 2) {
    // if the current number is not marked (it is prime)
    if (psieve[i] == 1) {
      // mark all the multiples of i as not prime
      for (ll j = i * i; j <= 1000000; j = j + i)
        psieve[j] = 0;
    }
  }
  // special case
  psieve[2] = 1;
  psieve[1] = psieve[0] = 0;
}

int main() {
  fio;
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  int n, m;
  cin >> n >> m;
  ll h[n + 1];
  vector<vector<int>> v(n + 1);
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    v[x].emplace_back(y);
    v[y].emplace_back(x);
  }
  /*  for(int i=1;i<v.size();i++)
    {
       cout<<i<<" ";
       for(int j=0;j<v[i].size();j++) cout<<v[i][j]<<" "; cout<<newl;
    }*/
  int count = 0;

  for (ll i = 1; i <= n; i++) {
    // cout<<i<<" ";
    int flag = 0;
    if (v[i].size() == 0ll) {
      count++;
    } else {
      // for(int j=0;j<v[i].size();j++) cout<<v[i][j]<<" "; cout<<newl;
      for (ll j = 0; j < v[i].size(); j++) {
        if (h[v[i][j]] >= h[i]) {
          flag = 1;
          break;
        }
      }
      if (flag == 0)
        count++;
    }
  }
  cout << count;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#include <math.h>
#include <numeric>
#include <stdio.h>
// #include "boost/algorithm/string.hpp"
#define fio                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define mod 1000000007
#define mod1 mod
#define mod2 1000000007
#define ll long long int
#define ull unsigned long long int
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#define readi(x) scanf("%d", &x)
#define reads(x) scanf("%s", x)
#define readl(x) scanf("%I64d", &x)
#define rep(i, n) for (i = 0; i < n; i++)
#define revp(i, n) for (i = (n - 1); i >= 0; i--)
#define myrep1(i, a, b) for (i = a; i <= b; i++)
#define myrep2(i, a, b) for (i = b; i >= a; i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define sec second
#define MAXN 1000000000000000005
#define MINN -1000000000000000000
#define INTMAX 1000001000
#define pii pair<ll, ll>
#define pdd pair<double, double>
#define pic pair<int, char>
#define lgn 20
#define ddouble long double
#define minus minu
#define PI 3.1415926535
#define lgn 20
#define coutd(x) cout << fixed << setprecision(x)
#define DECIMAL(n) std::cout << std::fixed << std::setprecision(n);
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define fil(v, x) fill(all(v), x)
#define filcon(v, x) iota(all(v), x)
#define newl '\\n'
#define sz(x) (int)x.size()
ull sqr(int x) { return 1ll * x * x; }

// #define INTMAX 200000000

// using namespace boost;
// #define si short int

using namespace std;
using namespace __gnu_pbds;
typedef priority_queue<ll, vector<ll>> max_pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> min_pq;
ll toint(const string &s) {
  stringstream ss;
  ss << s;
  ll x;
  ss >> x;
  return x;
}
string tostring(ll number) {
  stringstream ss;
  ss << number;
  return ss.str();
}
template <typename T> T toIntegralType(const string &str) {
  static_assert(is_integral<T>::value, "Integral type required.");
  T ret;
  stringstream ss(str);
  ss >> ret;
  if (to_string(ret) != str)
    throw invalid_argument("Can't convert " + str);
  return ret;
}
// using namespace __gnu_pbds;
// typedef priority_queue<pair<ll,char> , vector<pair<ll , char> > > max_pq;
// typedef priority_queue<pii , vector<pii > ,greater<pii > > min_pq;
typedef tree<pii, null_type, less<pii>, rb_tree_tag,
             tree_order_statistics_node_update>
    OST;
// typedef priority_queue<pair < ll , pair < pii , ll > >  , vector<pair < ll ,
// pair < pii , ll > >  > ,greater<pair < ll , pair < pii , ll > >  > > min_pq;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cout << name << " : " << arg1 << std::endl;
  // use cerr if u want to display at the bottom
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
#define nn 2000005
bool isPowerOfTwo(ll n) {
  if (n == 0)
    return false;

  return (ceil(log2(n)) == floor(log2(n)));
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
int psieve[1000005] = {0};
void prime_sieve() {
  // first mark all odd number prime
  for (int i = 3; i <= 1000000; i += 2) {
    psieve[i] = 1;
  }

  // Sieve
  for (ll i = 3; i <= 1000000; i += 2) {
    // if the current number is not marked (it is prime)
    if (psieve[i] == 1) {
      // mark all the multiples of i as not prime
      for (ll j = i * i; j <= 1000000; j = j + i)
        psieve[j] = 0;
    }
  }
  // special case
  psieve[2] = 1;
  psieve[1] = psieve[0] = 0;
}

int main() {
  fio;
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  int n, m;
  cin >> n >> m;
  ll h[n];
  vector<vector<int>> v(n + 1);
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    v[x].emplace_back(y);
    v[y].emplace_back(x);
  }
  /*  for(int i=1;i<v.size();i++)
    {
       cout<<i<<" ";
       for(int j=0;j<v[i].size();j++) cout<<v[i][j]<<" "; cout<<newl;
    }*/
  int count = 0;

  for (ll i = 1; i <= n; i++) {
    // cout<<i<<" ";
    int flag = 0;
    if (v[i].size() == 0) {
      count++;
    } else {
      // for(int j=0;j<v[i].size();j++) cout<<v[i][j]<<" "; cout<<newl;
      for (ll j = 0; j < v[i].size(); j++) {
        if (h[v[i][j]] >= h[i]) {
          flag = 1;
          break;
        }
      }
      if (flag == 0)
        count++;
    }
  }
  cout << count;
}