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

/*input
4 3
1 2 3 4
1 3
2 3
2 4
*/
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<ll, ll>
#define vi vector<long long>
#define vii vector<pii>
#define mi map<ll, ll>
#define mii map<pii, ll>
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define sz(x) (int)x.size()
#define endl '\\n'
#define hell 1000000007
#define mod 998244353
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define repi(i, a, b) for (ll i = a; i >= b; i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define mp make_pair
#define fIO                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define clr(x) memset(x, 0, sizeof(x))
#define debug(x) cerr << #x << "=" << x << endl
#define debug2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define TIME                                                                   \\
  cerr << "\\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\\n";
// #define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update>;

ll sub(ll a, ll b) { return (a - b + hell) % hell; }
ll add(ll a, ll b) { return (a + b) % hell; }
ll mul(ll a, ll b) { return (a * b) % hell; }
/*vector<ll>adj[100005];
bool vis[100005];
ll siz,edges;
void dfs(ll i)
{
    vis[i]=1;
    //siz++;
    for(ll j=0;j<adj[i].size();j++)
    {
        edges++;
        if(!vis[adj[i][j]])
            dfs(adj[i][j]);
    }
}
ll mpow(ll base, ll exp) {
  base %= hell;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % hell;
    base = ((ll)base * base) % hell;
    exp >>= 1;
  }
  return result;
}*/
int main() {
  fIO;
  ll n, sum = 0, t = 1, m, ans = 0;

  // cin >> t;
  while (t--) {
    // string s;
    cin >> n >> m;
    vi a(n + 1), b(n + 1, 1);
    rep(i, 1, n + 1) cin >> a[i];
    // vector<vi>v(n+1,vi(n+1));
    map<pii, ll> ma;

    rep(i, 0, m) {
      ll aa, bb;
      cin >> aa >> bb;
      ma[{aa, bb}] = 1;
    }
    tr(it, ma) {
      if (a[it->x.x] < a[it->x.y]) {
        b[it->x.x] &= 0;
        b[it->x.y] &= 1;
      } else if (a[it->x.x] == a[it->x.y]) {
        b[it->x.x] &= 0;
        b[it->x.y] &= 0;
      } else if (a[it->x.x] > a[it->x.y]) {
        b[it->x.x] &= 1;
        b[it->x.y] &= 0;
      }
    }
    rep(i, 1, n + 1) if (b[i] == 1) ans++;
    cout << ans << endl;
  }
  TIME;
}

Error: 0

Time elapsed: 0.028838 s.


Fixed submission:

/*input
6 5
8 6 9 1 2 1
1 3
4 2
4 3
4 6
4 6
*/
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<long, long>
#define vi vector<long long>
#define vii vector<pii>
#define mi map<ll, ll>
#define mii map<pii, ll>
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define sz(x) (int)x.size()
#define endl '\\n'
#define hell 1000000007
#define mod 998244353
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define repi(i, a, b) for (ll i = a; i >= b; i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define mp make_pair
#define fIO                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define clr(x) memset(x, 0, sizeof(x))
#define debug(x) cerr << #x << "=" << x << endl
#define debug2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define TIME                                                                   \\
  cerr << "\\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\\n";
// #define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update>;

ll sub(ll a, ll b) { return (a - b + hell) % hell; }
ll add(ll a, ll b) { return (a + b) % hell; }
ll mul(ll a, ll b) { return (a * b) % hell; }
/*vector<ll>adj[100005];
bool vis[100005];
ll siz,edges;
void dfs(ll i)
{
    vis[i]=1;
    //siz++;
    for(ll j=0;j<adj[i].size();j++)
    {
        edges++;
        if(!vis[adj[i][j]])
            dfs(adj[i][j]);
    }
}
ll mpow(ll base, ll exp) {
  base %= hell;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % hell;
    base = ((ll)base * base) % hell;
    exp >>= 1;
  }
  return result;
}*/
int main() {
  fIO;
  ll n, sum = 0, t = 1, m, ans = 0;

  // cin >> t;
  while (t--) {
    // string s;
    cin >> n >> m;
    vi a(n + 1), b(n + 1);
    rep(i, 1, n + 1) cin >> a[i];
    vector<vi> v(n + 1, vi(n + 1));

    rep(i, 0, m) {
      ll x, y;
      cin >> x >> y;
      if (a[x] < a[y] && b[y] != -1) {
        b[y] = 1;
        b[x] = -1;
      }
      if (a[x] == a[y]) {
        b[x] = -1;
        b[y] = -1;
      } else if (a[x] > a[y] && b[x] != -1) {
        b[x] = 1;
        b[y] = -1;
      }
    }

    rep(i, 1, n + 1) if (b[i] != -1) ans++;
    cout << ans << endl;
  }
  TIME;
}