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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO                                                                     \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI = acos(-1);
const ll INF = 1LL << 62;
const ll MINF = -(1LL << 62);

template <typename T> T getint() {
  T val = 0;
  char c;

  bool neg = false;
  while ((c = gc()) && !(c >= '0' && c <= '9')) {
    neg |= c == '-';
  }

  do {
    val = (val * 10) + c - '0';
  } while ((c = gc()) && (c >= '0' && c <= '9'));

  return val * (neg ? -1 : 1);
}

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// uniform_int_distribution<int>(0, n-1)(rng)

vector<int> adj[300001];
int main() {
  IO;
  int n, m;
  cin >> n >> m;
  vector<int> h(n + 1);
  for (int i = 1; i <= n; ++i)
    cin >> h[i];

  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    adj[a].pb(b);
    adj[b].pb(a);
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    bool ok = true;
    for (auto j : adj[i]) {
      ok &= h[j] < h[i];
    }
    ans += ok;
  }

  cout << ans << "\\n";

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO                                                                     \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI = acos(-1);
const ll INF = 1LL << 62;
const ll MINF = -(1LL << 62);

template <typename T> T getint() {
  T val = 0;
  char c;

  bool neg = false;
  while ((c = gc()) && !(c >= '0' && c <= '9')) {
    neg |= c == '-';
  }

  do {
    val = (val * 10) + c - '0';
  } while ((c = gc()) && (c >= '0' && c <= '9'));

  return val * (neg ? -1 : 1);
}

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// uniform_int_distribution<int>(0, n-1)(rng)

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>> adj(n + 1, vector<int>(n + 1));
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    adj[a].pb(b);
    adj[b].pb(a);
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    bool ok = true;
    for (auto j : adj[i]) {
      ok &= h[j] < h[i];
    }
    ans += ok;
  }

  cout << ans << "\\n";

  return 0;
}