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

// Author: Fuadul Hasan(fuadul202@gmail.com)
// BSMRSTU,Gopalganj
#include <bits/stdc++.h>
using namespace std;
int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding cin.tie(0);
#define mp make_pair
#define ll long long
#define Pi atan(1) * 4
#define pb push_back
#define vpr vector<pr>
#define pr pair<int, int>
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\\n");
#define NO printf("NO\\n");
#define Yes printf("Yes\\n");
#define No printf("No\\n");
#define all(n) n.begin(), n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ", tc++);
#define Unique(c) (c).resize(unique(all(c)) - (c).begin())
#define vout(v)                                                                \\
  for (auto z : v)                                                             \\
    cout << z << " ";                                                          \\
  cout << endl;

const int M = 1e9 + 7;
const ll Inf = (ll)2e18 + 5;
const int N = 2e5 + 5;

int solve() {
  // happy coding

  ll n, m;
  cin >> n >> m;
  ll a[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  ll cnt = 0;
  std::map<ll, bool> vis;
  for (int i = 0; i < m; i++) {
    ll x, y;
    cin >> x >> y;
    if (a[x] > a[y] && !vis[y]) {
      vis[y] = 1;
    } else if (a[x] < a[y] && !vis[x]) {
      vis[x] = 1;
    } else if (a[x] == a[y]) {
      if (vis[x] == 0 || vis[y] == 0)
        // cnt++;
        vis[x] = 1;
      vis[y] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i] == 0) {
      cnt++;
    }
  }
  cout << cnt << endl;

  return 0;
}
int main() {
  int test = 1;
  // scanf("%d", &test);
  while (test--)
    solve();
  return 0;
}

Error: 0

Fixed submission:

// Author: Fuadul Hasan(fuadul202@gmail.com)
// BSMRSTU,Gopalganj
#include <bits/stdc++.h>
using namespace std;
int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding cin.tie(0);
#define mp make_pair
#define ll long long
#define Pi atan(1) * 4
#define pb push_back
#define vpr vector<pr>
#define pr pair<int, int>
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\\n");
#define NO printf("NO\\n");
#define Yes printf("Yes\\n");
#define No printf("No\\n");
#define all(n) n.begin(), n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ", tc++);
#define Unique(c) (c).resize(unique(all(c)) - (c).begin())
#define vout(v)                                                                \\
  for (auto z : v)                                                             \\
    cout << z << " ";                                                          \\
  cout << endl;

const int M = 1e9 + 7;
const ll Inf = (ll)2e18 + 5;
const int N = 2e5 + 5;

int vis[N];

int solve() {
  // happy coding

  int n, m;
  cin >> n >> m;
  int a[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  ll cnt = 0;

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (a[x] >= a[y] && !vis[a[x]]) {
      vis[a[x]] = 1;
      cnt++;
    } else {
      if (!vis[a[y]]) {
        vis[a[y]] = 1;
        cnt++;
      }
    }
  }
  cout << cnt << endl;

  return 0;
}
int main() {
  int test = 1;
  // scanf("%d", &test);
  while (test--)
    solve();
  return 0;
}