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

#include <bits/stdc++.h>
#define rep(i, a, b) for (auto i = (a); i < (b); i++)
#define per(i, a, b) for (auto i = (a); i >= (b); i--)
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define int_inf 0x3f3f3f3f
#define int_max 2147483647
#define ll_max 9223372036854775807
#define ull_max 18446744073709551615
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lowbit(x) (x) & (-x)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const ll mod = 1e9 + 7;
template <class T> inline T read() {
  T x = 0, f = 1;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-')
      f = -1;
    s = getchar();
  };
  while (s >= '0' && s <= '9') {
    x = (x << 3) + (x << 1) + s - 48;
    s = getchar();
  };
  return x * f;
}
template <typename T> inline void wri(T x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  };
  if (x / 10)
    wri(x / 10);
  putchar(x % 10 + 48);
}
template <typename T> inline void print(T x, char s) {
  wri(x);
  putchar(s);
}
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
// 关闭流同步就不能手写读入优化啦
vector<int> a[1000001];
int n, m;
int p[1000001];
int vis[1000001];
int cnt;
map<pair<int, int>, int> p1;
void dfs(int node, int fa) {
  if (vis[node])
    return;
  vis[node] = 1;
  int flag = 0;
  for (auto u : a[node]) {
    if (p[u] < p[node]) {
      continue;
    } else
      flag = 1;
    // cout<<node<<" "<<u<<endl;
  }
  if (!flag) {
    // cout<<node<<endl;
    cnt++;
  }
  for (auto u : a[node]) {
    if (u != fa) {
      dfs(u, node);
    }
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n + 1) cin >> p[i];
  rep(i, 1, m + 1) {
    int x, y;
    cin >> x >> y;
    a[x].pb(y);
    a[y].pb(x);
  }
  rep(i, 1, n + 1) {
    if (!vis[i]) {
      // cout<<i<<endl;
      dfs(i, 0);
    }
  }
  cout << cnt << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, b) for (auto i = (a); i < (b); i++)
#define per(i, a, b) for (auto i = (a); i >= (b); i--)
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define int_inf 0x3f3f3f3f
#define int_max 2147483647
#define ll_max 9223372036854775807
#define ull_max 18446744073709551615
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lowbit(x) (x) & (-x)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const ll mod = 1e9 + 7;
template <class T> inline T read() {
  T x = 0, f = 1;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-')
      f = -1;
    s = getchar();
  };
  while (s >= '0' && s <= '9') {
    x = (x << 3) + (x << 1) + s - 48;
    s = getchar();
  };
  return x * f;
}
template <typename T> inline void wri(T x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  };
  if (x / 10)
    wri(x / 10);
  putchar(x % 10 + 48);
}
template <typename T> inline void print(T x, char s) {
  wri(x);
  putchar(s);
}
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
// 关闭流同步就不能手写读入优化啦
vector<int> a[1000001];
int n, m;
int p[1000001];
int vis[1000001];
int cnt;
void dfs(int node, int fa) {
  vis[node] = 1;
  int flag = 0;
  for (auto u : a[node]) {
    if (p[u] >= p[node]) {
      flag = 1;
    }
    // cout<<node<<" "<<u<<endl;
  }
  if (!flag) {
    // cout<<node<<endl;
    cnt++;
  }
  for (auto u : a[node]) {
    if (u != fa) {
      dfs(u, node);
    }
  }
}
map<pair<int, int>, int> p1;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n + 1) cin >> p[i];
  rep(i, 1, m + 1) {
    int x, y;
    cin >> x >> y;
    if (!p1[mp(x, y)] && !p1[mp(y, x)]) {
      a[x].pb(y);
      a[y].pb(x);
      p1[mp(x, y)] = p1[mp(y, x)] = 1;
    }
  }
  dfs(1, 0);
  rep(i, 1, n + 1) {
    if (!vis[i]) {
      // cout<<i<<endl;
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}