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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define int long long int
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)                                                                   \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
#define from(i, n) for (int i = 1; i <= (int)n; i++)
#define from_j(i, j, n) for (int i = j; i < (int)n; i++)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    pbds;

void c_p_c() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
  c_p_c();
  int n, m;
  cin >> n >> m;
  int weights[n + 1];
  weights[0] = 0;
  from(i, n) cin >> weights[i];
  int ans[n + 1];
  ans[0] = 0;
  from(i, n) ans[i] = 1;
  while (m--) {
    int a, b;
    cin >> a >> b;
    if (weights[a] > weights[b])
      ans[b] = 0;
    else if (weights[b] > weights[a])
      ans[a] = 0;
    else {
      ans[b] = 0;
      ans[a] = 0;
    }
  }
  int count = 0;
  from(i, n) {
    if (ans[i])
      count++;
  }
  cout << count;
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define int long long int
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)                                                                   \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
#define from(i, n) for (int i = 1; i <= (int)n; i++)
#define from_j(i, j, n) for (int i = j; i < (int)n; i++)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    pbds;

void c_p_c() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
  c_p_c();
  int n, m;
  cin >> n >> m;
  int weights[m + 1];
  weights[0] = 0;
  from(i, n) cin >> weights[i];
  // cout<<weights[n];
  int ans[n + 1];
  ans[0] = 0;
  from(i, n) ans[i] = 1;
  while (m--) {
    int a, b;
    cin >> a >> b;
    // cout<<a<<" "<<b<<" "<<weights[a]<<" "<<weights[b]<<endl;
    if (weights[a] > weights[b])
      ans[b] = 0;
    else if (weights[b] > weights[a])
      ans[a] = 0;
    else {
      ans[b] = 0;
      ans[a] = 0;
    }
  }
  int count = 0;
  from(i, n) {
    // cout<<ans[i]<<" ";
    if (ans[i])
      count++;
  }
  // cout<<endl;
  cout << count;
  return 0;
}