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

#include <bits/stdc++.h>
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define vvb vector<vb>
#define pb push_back
#define inf 1e18
#define mod 1000000007
#define ps(x, y) fixed << setpricision(y) << x
#define w(t)                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define FIO                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define PI 3.14159265358979323846
using namespace std;
const int N = 300 * 1000 + 13;
void init() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}
int32_t main() {
  FIO;
  init();
  int n, k;
  cin >> n >> k;
  vi weight(n + 1);
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    weight[i] = x;
  }
  map<int, set<int>> m;
  while (k--) {
    int x, y;
    cin >> x >> y;
    m[x].insert(y);
    m[y].insert(x);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int c = 0;
    if (m[i].size() == 0)
      ans++;
    else {
      for (int x : m[i]) {
        if (weight[i] > weight[x])
          c++;
      }
      if (c == m[i].size())
        ans++;
    }
  }
  cout << ans << '\\n';
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define vvb vector<vb>
#define pb push_back
#define inf 1e18
#define mod 1000000007
#define ps(x, y) fixed << setpricision(y) << x
#define w(t)                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define FIO                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define PI 3.14159265358979323846
using namespace std;
const int N = 300 * 1000 + 13;
void init() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}
int32_t main() {
  FIO;
  init();
  int n, k;
  cin >> n >> k;
  vi weight(n + 1);
  vi g[(n + 1)];
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    weight[i] = x;
  }
  bool check[n + 1][n + 1];
  while (k--) {
    int x, y;
    cin >> x >> y;
    if (check[x][y] == false && x != y) {
      g[x].push_back(y);
      g[y].push_back(x);
      check[x][y] = true;
    }
  }
  int c = 0, ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int x : g[i]) {
      if (weight[i] > weight[x])
        c++;
    }
    if (c == g[i].size())
      ans++;
  }
  cout << (ans + 1) << '\\n';
}