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
#define ll long long
#define pb push_back
#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 zerobits(x) __builtin_ctzll(x)
#define mod 998244353
#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 vpii vector<pair<int, int>>
#define all(x) x.begin(), x.end()
#define gcd(m, n) __gcd(m, n)
#define matrixprint(arr, a, b, c, d)                                           \\
  for (int i = a; i <= c; i++) {                                               \\
    for (int j = b; j <= d; j++) {                                             \\
      cout << arr[i][j] << " ";                                                \\
    }                                                                          \\
    cout << "\\n";                                                              \\
  }
#define show(arr, x, y)                                                        \\
  for (int i = x; i <= y; i++) {                                               \\
    cout << arr[i] << " ";                                                     \\
  }                                                                            \\
  cout << "\\n"
#define sz size()
#define inc(i, x, y) for (int i = x; i <= y; i++)
#define dec(i, x, y) for (int i = x; i >= y; i--)

#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define deb(...)
#endif

void fast() {
  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
}

//////////////////////////////code//////////////////////////////
vi arr(100001);
vi adj[100001];
int ctr;
int vis[100001];

void dfs(int node) {
  vis[node]++;

  int f = 0;

  // deb(node);

  for (int i = 0; i < adj[node].size(); i++) {
    if (arr[adj[node][i]] >= arr[node])
      f = 1;

    if (!vis[adj[node][i]])
      dfs(adj[node][i]);
  }

  if (f == 0) {
    ctr++;
    // deb(f,node);
  }
}

int32_t main() {
  fast();
  memset(vis, 0, sizeof(vis));
  int n, m;
  cin >> n >> m;

  inc(i, 1, n) cin >> arr[i];

  inc(i, 0, m - 1) {
    int u, v;
    cin >> u >> v;

    adj[u].pb(v);
    adj[v].pb(u);
  }

  ctr = 0;
  // deb(adj[5].sz);
  for (int i = 1; i <= n; i++) { // deb(i,vis[i],vis[6]);
    if (!vis[i])
      dfs(i);
  }

  cout << ctr;
}


Error: WA

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
#define ll long long
#define pb push_back
#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 zerobits(x) __builtin_ctzll(x)
#define mod 998244353
#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 vpii vector<pair<int, int>>
#define all(x) x.begin(), x.end()
#define gcd(m, n) __gcd(m, n)
#define matrixprint(arr, a, b, c, d)                                           \\
  for (int i = a; i <= c; i++) {                                               \\
    for (int j = b; j <= d; j++) {                                             \\
      cout << arr[i][j] << " ";                                                \\
    }                                                                          \\
    cout << "\\n";                                                              \\
  }
#define show(arr, x, y)                                                        \\
  for (int i = x; i <= y; i++) {                                               \\
    cout << arr[i] << " ";                                                     \\
  }                                                                            \\
  cout << "\\n"
#define sz size()
#define inc(i, x, y) for (int i = x; i <= y; i++)
#define dec(i, x, y) for (int i = x; i >= y; i--)

#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define deb(...)
#endif

void fast() {
  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
}

//////////////////////////////code//////////////////////////////
vi arr(100001);
vi adj[100001];
int ctr;
int vis[100001];

void dfs(int node) {
  vis[node]++;

  int f = 0;

  inc(i, 0, adj[node].sz - 1) {
    if (arr[adj[node][i]] >= arr[node])
      f = 1;

    if (!vis[adj[node][i]])
      dfs(adj[node][i]);
  }

  if (f == 0)
    ctr++;
}

int32_t main() {
  fast();
  memset(vis, 0, sizeof(vis));
  int n, m;
  cin >> n >> m;

  inc(i, 1, n) cin >> arr[i];

  inc(i, 0, m - 1) {
    int u, v;
    cin >> u >> v;
    adj[u].pb(v);
    adj[v].pb(u);
  }

  ctr = 0;
  dfs(1);

  cout << ctr;
}