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

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

typedef long long ll;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};
const int INF = 1e9;
#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
int guki(int a) {
  if (a % 2 == 0)
    return 0;
  else
    return 1;
}
int gcd(int a, int b) {
  if (a % b == 0) {
    return b;
  } else {
    return (gcd(b, a % b));
  }
}
int lcm(int a, int b) {
  int x = gcd(a, b);
  return (a * b / x);
}

using namespace std;
// now

struct UnionFind {
  vector<int> d;
  UnionFind(int n = 0) : d(n, -1) {}
  int Find(int x) { // 根の番号を探す
    if (d[x] < 0)
      return x;
    return d[x] = Find(d[x]);
  }
  bool unite(int x, int y) {
    x = Find(x);
    y = Find(y);
    if (x == y)
      return false;
    if (d[x] < d[y]) {
      swap(x, y);
    }
    d[x] += d[y];
    d[y] = x;
    return true;
  }

  bool same(int x, int y) { return Find(x) == Find(y); }
  int size(int x) { return (-d[Find(x)]); }
};

ll nCr(ll n, ll r) {
  ll ans = 1;
  for (ll i = n; i > n - r; i--) {
    ans *= i;
  }
  for (ll i = 1; i <= r; i++) {
    ans /= i;
  }
  return ans;
}

int nPr(int n, int r) {
  int ans = 1;
  for (int i = n; i > n - r; i--) {
    ans *= i;
  }
  return ans;
}
ll modd = 1e9 + 7;
ll wa(ll n, ll mi, ll ma) {
  ll ans = n * (mi + ma) / 2;
  return ans;
}

int main() {
  int n, m;
  cin >> n >> m;

  vector<int> vm(n), v(n);
  REP(i, n) {
    cin >> v[i];
    vm[i] = 0;
  }
  int a, b;
  REP(i, m) {
    cin >> a >> b;
    a--;
    b--;
    vm[a] = max(vm[a], v[b]);
    vm[b] = max(vm[b], v[a]);
  }
  int ans = 0;
  REP(i, n) {
    bool fl = true;
    if (v[i] <= vm[i])
      fl = false;
    if (fl)
      ans++;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

typedef long long ll;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};
const int INF = 1e9;
#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
int guki(int a) {
  if (a % 2 == 0)
    return 0;
  else
    return 1;
}
int gcd(int a, int b) {
  if (a % b == 0) {
    return b;
  } else {
    return (gcd(b, a % b));
  }
}
int lcm(int a, int b) {
  int x = gcd(a, b);
  return (a * b / x);
}

using namespace std;
// now

struct UnionFind {
  vector<int> d;
  UnionFind(int n = 0) : d(n, -1) {}
  int Find(int x) { // 根の番号を探す
    if (d[x] < 0)
      return x;
    return d[x] = Find(d[x]);
  }
  bool unite(int x, int y) {
    x = Find(x);
    y = Find(y);
    if (x == y)
      return false;
    if (d[x] < d[y]) {
      swap(x, y);
    }
    d[x] += d[y];
    d[y] = x;
    return true;
  }

  bool same(int x, int y) { return Find(x) == Find(y); }
  int size(int x) { return (-d[Find(x)]); }
};

ll nCr(ll n, ll r) {
  ll ans = 1;
  for (ll i = n; i > n - r; i--) {
    ans *= i;
  }
  for (ll i = 1; i <= r; i++) {
    ans /= i;
  }
  return ans;
}

int nPr(int n, int r) {
  int ans = 1;
  for (int i = n; i > n - r; i--) {
    ans *= i;
  }
  return ans;
}
ll modd = 1e9 + 7;
ll wa(ll n, ll mi, ll ma) {
  ll ans = n * (mi + ma) / 2;
  return ans;
}

int main() {
  int n, m;
  cin >> n >> m;

  vector<vector<int>> vec(n, vector<int>(n));
  vector<int> v(n);
  REP(i, n) { cin >> v[i]; }
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    vec[a][b] = 1;
    vec[b][a] = 1;
  }
  int ans = 0;

  REP(i, n) {
    bool fl = true;
    bool fl2 = true;
    REP(j, n) {
      if (vec[i][j] == 1) {
        fl2 = false;
        if (v[i] <= v[j])
          fl = false;
      }
    }

    if (fl) {
      ans++;
    }
  }
  cout << ans << endl;
}