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

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

/*----------macros----------*/

// output================
#define endl '\\n'
#define fcout cout << fixed << setprecision(15)

// typedef===============
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

// const number==========
constexpr ll INF9 = (ll)1e9 + 1;
constexpr ll INF18 = (ll)1e18 + 1;
constexpr ll MOD = 1000000007;
constexpr ld PI = 3.141592653589793L;

// member================
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

// others================
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; (i) < (int)(n); (i)++)
#define rrep(i, n) for (int i = n - 1; (i) >= 0; (i)--)
#define For(i, a, b) for (int i = (a); (i) < (int)(b); (i)++)
#define CtoI(c) int((c)) - int('0')

// functions=============
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

// vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/

bool judge(vector<vector<int>> &_G, vector<ll> &_h, int p) {

  for (auto x : _G[p]) {
    if (_h[p] <= _h[x])
      return false;
  }

  return true;
}

/*----------main------------*/

int main() {
  /*----------fastio----------*/
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  std::ios::sync_with_stdio(false);
  /*----------solve-----------*/

  int n, m;
  cin >> n >> m;
  vector<ll> h(n + 1);
  For(i, 1, n + 1) cin >> h[i];
  vector<vector<int>> G(n + 1);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    G[a].pb(b);
    G[b].pb(a);
  }

  ll ans = 0;
  For(i, 1, n + 1) {
    if (judge(G, h, i))
      ans++;
  }

  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

/*----------macros----------*/

// output================
#define endl '\\n'
#define fcout cout << fixed << setprecision(15)

// typedef===============
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

// const number==========
constexpr ll INF9 = (ll)1e9 + 1;
constexpr ll INF18 = (ll)1e18 + 1;
constexpr ll MOD = 1000000007;
constexpr ld PI = 3.141592653589793L;

// member================
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

// others================
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; (i) < (int)(n); (i)++)
#define rrep(i, n) for (int i = n - 1; (i) >= 0; (i)--)
#define For(i, a, b) for (int i = (a); (i) < (int)(b); (i)++)
#define CtoI(c) int((c)) - int('0')

// functions=============
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

// vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/

bool judge(vector<vector<int>> &_G, vector<ll> &_h, int p) {

  for (auto x : _G[p]) {
    if (_h[p] <= _h[x])
      return false;
  }

  return true;
}

/*----------main------------*/

int main() {
  /*----------fastio----------*/
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  std::ios::sync_with_stdio(false);
  /*----------solve-----------*/

  int n, m;
  cin >> n >> m;
  vector<ll> h(n + 1);
  For(i, 1, n) cin >> h[i];
  vector<vector<int>> G(n + 1);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    G[a].pb(b);
    G[b].pb(a);
  }

  ll ans = 0;
  For(i, 1, n) {
    if (judge(G, h, i))
      ans++;
  }

  cout << ans << endl;

  return 0;
}