prithivMLmods/Coder-Stat huggingface dataset:
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) loop(i, 0, n)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>

int main() {
  ll int n, m;
  cin >> n >> m;
  vl h(n);
  rep(i, n) cin >> h[i];
  vl a(m), b(m);
  rep(i, m) cin >> a[i] >> b[i];
  vector<vector<int>> net(n);

  rep(i, m) {
    net[a[i] - 1].push_back(b[i] - 1);
    net[b[i] - 1].push_back(a[i] - 1);
  }

  rep(i, m) { sort(all(net[i])); }

  int ans = 0;
  rep(i, n) {
    ll int hi = h[i];
    int flag = 0;
    int ini;
    if (net[i].size() > 0) {
      ini = net[i][0];
      for (long unsigned int j = 0; j < net[i].size(); j++) {
        if (j != 0 && ini == net[i][j])
          continue;
        if (hi <= h[net[i][j]]) {
          ini = net[i][j];
          flag = 1;
        }
      }
    }

    if (flag == 0)
      ans++;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) loop(i, 0, n)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>

int main() {
  ll int n, m;
  cin >> n >> m;
  vl h(n);
  rep(i, n) cin >> h[i];
  vl a(m), b(m);
  rep(i, m) cin >> a[i] >> b[i];
  vector<vector<int>> net(n);

  rep(i, m) {
    net[a[i] - 1].push_back(b[i] - 1);
    net[b[i] - 1].push_back(a[i] - 1);
  }

  rep(i, n) { sort(all(net[i])); }

  int ans = 0;
  rep(i, n) {
    ll int hi = h[i];
    int flag = 0;
    int ini;
    if (net[i].size() > 0) {
      ini = net[i][0];
      for (long unsigned int j = 0; j < net[i].size(); j++) {
        if (j != 0 && ini == net[i][j])
          continue;
        if (hi <= h[net[i][j]]) {
          ini = net[i][j];
          flag = 1;
        }
      }
    }

    if (flag == 0)
      ans++;
  }
  cout << ans << endl;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 100010;
int h[N];
struct edge {
  int v;
  int next;
} e[N];
int p[N], eid;
void init() {
  memset(p, -1, sizeof(p));
  eid = 0;
}
void insert(int u, int v) {
  e[eid].v = v;
  e[eid].next = p[u];
  p[u] = eid++;
}
int main() {
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);
  ios::sync_with_stdio(false);
  init();
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    insert(u, v);
    insert(v, u);
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    int maxn = -1;
    for (int j = p[i]; j != -1; j = e[j].next) {
      int v = e[j].v;
      maxn = max(maxn, h[v]);
    }
    if (h[i] > maxn) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Fixed submission:
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 100010;
int h[N];
struct edge {
  int v;
  int next;
} e[2 * N];
int p[N], eid;
void init() {
  memset(p, -1, sizeof(p));
  eid = 0;
}
void insert(int u, int v) {
  e[eid].v = v;
  e[eid].next = p[u];
  p[u] = eid++;
}
int main() {
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);
  ios::sync_with_stdio(false);
  init();
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    insert(u, v);
    insert(v, u);
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    int maxn = -1;
    for (int j = p[i]; j != -1; j = e[j].next) {
      int v = e[j].v;
      maxn = max(maxn, h[v]);
    }
    if (h[i] > maxn) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

// 短縮
#define rep(i, n) for (int i = 0; i < (n); ++i)
// sort()用
#define all(v) v.begin(), v.end()

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  rep(i, N) cin >> H.at(i);
  vector<int> A(M);
  vector<int> B(M);
  vector<int> NN(N);
  vector<vector<int>> path(N, vector<int>(M));

  rep(i, M) { cin >> A.at(i) >> B.at(i); }
  rep(i, N) { NN.at(i) = 1; }

  rep(i, M) {
    if (H.at(A.at(i) - 1) > H.at(B.at(i) - 1)) {
      NN.at(B.at(i) - 1) = 0;
    } else if (H.at(A.at(i) - 1) == H.at(B.at(i) - 1)) {
      NN.at(B.at(i) - 1) = 0;
      NN.at(A.at(i) - 1) = 0;
    } else {
      NN.at(A.at(i) - 1) = 0;
    }
  }

  int sum = 0;
  rep(i, N) {
    if (NN.at(i) == 1) {
      sum++;
    }
  }
  cout << sum;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

// 短縮
#define rep(i, n) for (int i = 0; i < (n); ++i)
// sort()用
#define all(v) v.begin(), v.end()

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  rep(i, N) cin >> H.at(i);
  vector<int> A(M);
  vector<int> B(M);
  vector<int> NN(N);

  rep(i, M) { cin >> A.at(i) >> B.at(i); }
  rep(i, N) { NN.at(i) = 1; }

  rep(i, M) {
    if (H.at(A.at(i) - 1) > H.at(B.at(i) - 1)) {
      NN.at(B.at(i) - 1) = 0;
    } else if (H.at(A.at(i) - 1) == H.at(B.at(i) - 1)) {
      NN.at(B.at(i) - 1) = 0;
      NN.at(A.at(i) - 1) = 0;
    } else {
      NN.at(A.at(i) - 1) = 0;
    }
  }

  int sum = 0;
  rep(i, N) {
    if (NN.at(i) == 1) {
      sum++;
    }
  }
  cout << sum;
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define PI 3.14159265358979323846264338327950L

ll res = 0;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  ll N, M;
  cin >> N >> M;
  vector<ll> H(N);
  vector<ll> ma(N);
  for (int i = 1; i <= N; i++) {
    cin >> H[i];
    ma[i] = 0;
  }
  for (int i = 0; i < M; i++) {
    ll a, b;
    cin >> a >> b;
    ma[a] = max(ma[a], H[b]);
    ma[b] = max(ma[b], H[a]);
  }
  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += H[i] > ma[i];
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define PI 3.14159265358979323846264338327950L

ll res = 0;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  ll N, M;
  cin >> N >> M;
  vector<ll> H(N + 50);
  vector<ll> ma(N + 50);
  for (int i = 1; i <= N; i++) {
    cin >> H[i];
    ma[i] = 0;
  }
  for (int i = 0; i < M; i++) {
    ll a, b;
    cin >> a >> b;
    ma[a] = max(ma[a], H[b]);
    ma[b] = max(ma[b], H[a]);
  }
  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += H[i] > ma[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  int n, m, h[100010];
  int a[100010], b[100010];

  cin >> n >> m;
  rep(i, n) { cin >> h[i]; }
  rep(i, m) { cin >> a[i] >> b[i]; }

  bool ans[100010];

  rep(i, n) { ans[i] = true; }

  rep(j, n) {

    rep(i, m) {
      if (a[i] == j + 1 && h[a[i] - 1] <= h[b[i] - 1]) {
        ans[j] = false;
        break;
      }

      if (b[i] == j + 1 && h[a[i] - 1] >= h[b[i] - 1]) {
        ans[j] = false;
        break;
      }
    }
  }

  int cnt = 0;
  rep(i, n) {
    if (ans[i] == true)
      cnt++;
  }

  cout << cnt << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  int n, m, h[100010];
  int a[100010], b[100010];

  cin >> n >> m;
  rep(i, n) { cin >> h[i]; }
  rep(i, m) { cin >> a[i] >> b[i]; }

  bool ans[100010];

  rep(i, n) { ans[i] = true; }

  rep(i, m) {
    int atai = h[a[i] - 1] - h[b[i] - 1];
    if (atai <= 0)
      ans[a[i] - 1] = false;
    if (atai >= 0)
      ans[b[i] - 1] = false;
  }

  int cnt = 0;
  rep(i, n) {
    if (ans[i] == true)
      cnt++;
  }

  cout << cnt << endl;

  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define exrep(i, a, b) for (long long i = a; i <= b; i++)
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll>> vvl;
typedef vector<vector<P>> vvp;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const int MAX = 510000;
const double pi = acos(-1);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n, m;
  cin >> n >> m;
  vector<ll> h(n);
  vector<bool> ok(n, true);
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    if (h[a] <= h[b])
      ok[a] = false;
    if (h[b] <= h[a])
      ok[b] = false;
  }
  ll cnt = 0;
  rep(i, n) {
    if (ok[i])
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define exrep(i, a, b) for (long long i = a; i <= b; i++)
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll>> vvl;
typedef vector<vector<P>> vvp;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const int MAX = 510000;
const double pi = acos(-1);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n, m;
  cin >> n >> m;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  vector<bool> ok(n, true);
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    if (h[a] <= h[b])
      ok[a] = false;
    if (h[b] <= h[a])
      ok[b] = false;
  }
  ll cnt = 0;
  rep(i, n) {
    if (ok[i])
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<vector<int>> v(n + 1);
  vector<int> f(n + 1);
  vector<pair<long long, int>> arr;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    f[i + 1] = x;
    arr.emplace_back(x, i + 1);
  }
  sort(arr.rbegin(), arr.rend());
  for (; k--;) {
    int c, d;
    cin >> n >> d;
    v[n].push_back(d);
    v[d].push_back(n);
  }
  vector<bool> vis(n + 1, 0);
  int cnt = 0;
  for (auto i : arr) {
    if (!vis[i.second]) {
      bool flg = 1;
      // cout<<i.second<<" ";
      vis[i.second] = 1;
      for (int j : v[i.second]) {
        if (i.first <= f[j]) {
          flg = 0;
          break;
        }
        vis[j] = 1;
        // cout<<j<<" ";
      }
      // cout<<"\n";
      cnt += flg;
    }
  }
  cout << cnt << "\n";

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<vector<int>> v(n + 1);
  vector<int> f(n + 1);
  vector<pair<long long, int>> arr;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    f[i + 1] = x;
    arr.emplace_back(x, i + 1);
  }
  sort(arr.rbegin(), arr.rend());
  for (; k--;) {
    int c, d;
    cin >> c >> d;
    v[c].push_back(d);
    v[d].push_back(c);
  }
  vector<bool> vis(n + 1, 0);
  int cnt = 0;
  for (auto i : arr) {
    if (!vis[i.second]) {
      bool flg = 1;
      // cout<<i.second<<" ";
      vis[i.second] = 1;
      for (int j : v[i.second]) {
        if (i.first <= f[j]) {
          flg = 0;
          break;
        }
        vis[j] = 1;
        // cout<<j<<" ";
      }
      // cout<<"\n";
      cnt += flg;
    }
  }
  cout << cnt << "\n";

  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long int lld;
typedef unsigned long long int llu;
#define INF (lld)(9223372036854775807)
#define IINF (int)(2147483647)

using namespace std;
int main(void) {
  lld n, m, a, b, s = 0;
  cin >> n >> m;
  vector<lld> h(n);
  for (lld i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<vector<int>> p(10000);
  for (lld i = 0; i < m; i++) {
    cin >> a >> b;
    p[a - 1].push_back(b - 1);
    p[b - 1].push_back(a - 1);
  }

  for (lld i = 0; i < n; i++) {
    for (auto &t : p[i]) {
      if (h[t] >= h[i]) {
        goto no;
      }
    }
    s++;
  no:;
  }

  cout << s << "\n";
}

Fixed submission:
#include <bits/stdc++.h>
typedef long long int lld;
typedef unsigned long long int llu;
#define INF (lld)(9223372036854775807)
#define IINF (int)(2147483647)

using namespace std;
int main(void) {
  lld n, m, a, b, s = 0;
  cin >> n >> m;
  vector<lld> h(n);
  for (lld i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<vector<int>> p(n);
  for (lld i = 0; i < m; i++) {
    cin >> a >> b;
    p[a - 1].push_back(b - 1);
    p[b - 1].push_back(a - 1);
  }

  for (lld i = 0; i < n; i++) {
    for (auto &t : p[i]) {
      if (h[t] >= h[i]) {
        goto no;
      }
    }
    s++;
  no:;
  }

  cout << s << "\n";
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> h(n);
  rep(i, n) { cin >> h[i]; }
  vector<ll> a(n);
  vector<ll> b(m);
  vector<ll> judge(n);
  rep(i, m) {
    cin >> a[i] >> b[i];
    if (h[a[i] - 1] < h[b[i] - 1]) {
      judge[a[i] - 1] = 1;
    } else if (h[a[i] - 1] > h[b[i] - 1]) {
      judge[b[i] - 1] = 1;
    } else {
      judge[a[i] - 1] = 1;
      judge[b[i] - 1] = 1;
    }
  }
  ll ans = 0;
  rep(i, n) {
    if (judge[i] == 0) {
      ans++;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> h(n);
  rep(i, n) { cin >> h[i]; }
  vector<ll> a(m);
  vector<ll> b(m);
  vector<ll> judge(n);
  rep(i, m) {
    cin >> a[i] >> b[i];
    if (h[a[i] - 1] < h[b[i] - 1]) {
      judge[a[i] - 1] = 1;
    } else if (h[a[i] - 1] > h[b[i] - 1]) {
      judge[b[i] - 1] = 1;
    } else {
      judge[a[i] - 1] = 1;
      judge[b[i] - 1] = 1;
    }
  }
  ll ans = 0;
  rep(i, n) {
    if (judge[i] == 0) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define INF 100000000000
#define MOD 100000007 // 10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

char s[50][50];
int h, w;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  rep(i, n) cin >> h[i];

  vector<vector<int>> arr(n);
  int a, b;
  rep(i, m) {
    cin >> a >> b;
    a--;
    b--;
    arr[a].push_back(b);
    arr[b].push_back(a);
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    int flag = 1;
    for (int j = 0; j < sizeof(arr[i]); j++) {
      if (h[i] < h[arr[i][j]]) {
        flag = 0;
      }
    }
    if (flag)
      ans++;
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define INF 100000000000
#define MOD 100000007 // 10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

char s[50][50];
int h, w;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  rep(i, n) cin >> h[i];

  vector<vector<int>> arr(n);
  int a, b;
  rep(i, m) {
    cin >> a >> b;
    a--;
    b--;
    arr[a].push_back(b);
    arr[b].push_back(a);
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    int flag = 1;
    if (arr[i].size() == 0) {
      ans++;
      continue;
    }
    for (int j = 0; j < arr[i].size(); j++) {
      if (h[i] <= h[arr[i][j]]) {
        flag = 0;
      }
    }
    if (flag)
      ans++;
  }
  cout << ans << endl;

  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)                                                              \
  ;                                                                            \
  for (ll i = 1; i <= n; ++i)
using ll = long long;
using P = pair<int, int>;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> h(n + 10);
  rep(i, n) cin >> h[i];
  vector<ll> a(m + 10);
  vector<ll> b(m + 10);
  rep(i, m) cin >> a[i] >> b[i];
  vector<ll> ans(n);
  rep(i, n) ans[i] = 0;
  rep(i, m) {
    if (h[a[i]] >= h[b[i]])
      ++ans[b[i]];
    if (h[a[i]] <= h[b[i]])
      ++ans[a[i]];
  }
  ll count = 0;
  rep(i, n) {
    if (ans[i] == 0)
      ++count;
  }
  cout << count << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)                                                              \
  ;                                                                            \
  for (ll i = 1; i <= n; ++i)
using ll = long long;
using P = pair<int, int>;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> h(n + 10);
  rep(i, n) cin >> h[i];
  vector<ll> a(m + 10);
  vector<ll> b(m + 10);
  rep(i, m) cin >> a[i] >> b[i];
  vector<ll> ans(n + 10);
  rep(i, n) ans[i] = 0;
  rep(i, m) {
    if (h[a[i]] >= h[b[i]])
      ++ans[b[i]];
    if (h[a[i]] <= h[b[i]])
      ++ans[a[i]];
  }
  ll count = 0;
  rep(i, n) {
    if (ans[i] == 0)
      ++count;
  }
  cout << count << endl;
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  int N, M;
  cin >> N >> M;
  int H[M];
  int ans[N];
  rep(i, N) {
    cin >> H[i];
    ans[i] = 1;
  }

  rep(i, M) {
    int A, B;
    cin >> A >> B;
    if (H[A - 1] < H[B - 1]) {
      ans[A - 1] = 0;
    } else if (H[A - 1] > H[B - 1]) {
      ans[B - 1] = 0;
    }

    else {
      ans[A - 1] = 0;
      ans[B - 1] = 0;
    }
  }

  int sum_ = 0;
  rep(i, N) { sum_ += ans[i]; }
  cout << sum_ << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  int N, M;
  cin >> N >> M;
  int H[N];
  int ans[N];
  rep(i, N) {
    cin >> H[i];
    ans[i] = 1;
  }

  rep(i, M) {
    int A, B;
    cin >> A >> B;
    if (H[A - 1] < H[B - 1]) {
      ans[A - 1] = 0;
    } else if (H[A - 1] > H[B - 1]) {
      ans[B - 1] = 0;
    }

    else {
      ans[A - 1] = 0;
      ans[B - 1] = 0;
    }
  }

  int sum_ = 0;
  rep(i, N) { sum_ += ans[i]; }
  cout << sum_ << endl;

  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int ans, h[100000], n, m, x, y, l;
vector<int> ar[100000];
bool ok;

int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    ar[x].push_back(y);
    ar[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    l = ar[i].size();
    ok = true;
    for (int j = 0; j < l; j++) {
      if (h[i] <= h[ar[i][j]])
        ok = false;
      // cout<<i<<" "<<h[i]<<" "<<h[ar[i][j]]<<"\n";
    }
    if (ok == true)
      ans++;
    // cout<<h[i]<<" "<<h[ar[i][j]]<<"\n";
  }
  cout << ans << "\n";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int ans, h[100002], n, m, x, y, l;
vector<int> ar[100002];
bool ok;

int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    ar[x].push_back(y);
    ar[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    l = ar[i].size();
    ok = true;
    for (int j = 0; j < l; j++) {
      if (h[i] <= h[ar[i][j]])
        ok = false;
      // cout<<i<<" "<<h[i]<<" "<<h[ar[i][j]]<<"\n";
    }
    if (ok == true)
      ans++;
    // cout<<h[i]<<" "<<h[ar[i][j]]<<"\n";
  }
  cout << ans << "\n";
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string.h>
#include <vector>

using namespace std;

int main() {

  long long int N, M;
  long long int A, B;
  long long int count = 0;

  cin >> N >> M;
  long long int tab[N + 5];           // obs
  vector<long long int> cores[10005]; // linked roads

  for (long long int i = 1; i <= N; i++) {
    cin >> tab[i];
  }

  for (long long int i = 0; i < M; i++) {
    cin >> A >> B; // road A linked to B
    cores[A].push_back(B);
    cores[B].push_back(A);
  }

  for (long long int i = 1; i <= N; ++i) {

    bool good = true;
    for (long long int it : cores[i]) {
      if (tab[it] >= tab[i]) {
        good = false;
        break;
      }
    }
    if (good) {
      count++;
    }
  }

  cout << count;

  return 0;
}

Fixed submission:
#include <iostream>
#include <string.h>
#include <vector>

using namespace std;

int main() {

  long long int N, M;
  long long int A, B;
  long long int count = 0;

  cin >> N >> M;
  long long int tab[N + 5];            // obs
  vector<long long int> cores[100005]; // linked roads

  for (long long int i = 1; i <= N; i++) {
    cin >> tab[i];
  }

  for (long long int i = 0; i < M; i++) {
    cin >> A >> B; // road A linked to B
    cores[A].push_back(B);
    cores[B].push_back(A);
  }

  for (long long int i = 1; i <= N; ++i) {

    bool good = true;
    for (long long int it : cores[i]) {
      if (tab[it] >= tab[i]) {
        good = false;
        break;
      }
    }
    if (good) {
      count++;
    }
  }

  cout << count;

  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> road(n, vector<int>(n, 0));
  vector<int> h(n);
  vector<bool> flag(n, true);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  int tmp_a, tmp_b;
  for (int i = 0; i < m; i++) {
    cin >> tmp_a >> tmp_b;
    /*
    road[tmp_a-1][tmp_b-1]=1;
    road[tmp_b-1][tmp_a-1]=1;
    */
    if (h[tmp_a - 1] > h[tmp_b - 1])
      flag[tmp_b - 1] = false;
    if (h[tmp_a - 1] < h[tmp_b - 1])
      flag[tmp_a - 1] = false;
    if (h[tmp_a - 1] == h[tmp_b - 1]) {
      flag[tmp_b - 1] = false;
      flag[tmp_a - 1] = false;
    }
  }
  int ans = 0;
  // bool flag=true;
  for (int i = 0; i < n; i++) {
    if (flag[i]) {
      ans++;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  // vector<vector<int>> road(n,vector<int>(n,0));
  vector<int> h(n);
  vector<bool> flag(n, true);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  int tmp_a, tmp_b;
  for (int i = 0; i < m; i++) {
    cin >> tmp_a >> tmp_b;
    /*
    road[tmp_a-1][tmp_b-1]=1;
    road[tmp_b-1][tmp_a-1]=1;
    */
    if (h[tmp_a - 1] > h[tmp_b - 1])
      flag[tmp_b - 1] = false;
    if (h[tmp_a - 1] < h[tmp_b - 1])
      flag[tmp_a - 1] = false;
    if (h[tmp_a - 1] == h[tmp_b - 1]) {
      flag[tmp_b - 1] = false;
      flag[tmp_a - 1] = false;
    }
  }
  int ans = 0;
  // bool flag=true;
  for (int i = 0; i < n; i++) {
    if (flag[i]) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  int n, m;
  cin >> n >> m;
  int cnt = n;
  set<int> st;
  vector<int> h;
  rep(i, n) { cin >> h[i]; }
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    int x, y;
    x = h[a - 1];
    y = h[b - 1];
    int mn = min(x, y);
    if (x == y) {
      st.insert(a);
      st.insert(b);
    } else if (mn == x) {
      st.insert(a);
    } else if (mn == y) {
      st.insert(b);
    }
  }
  cnt -= st.size();
  cout << cnt << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  int n, m;
  cin >> n >> m;
  int cnt = n;
  set<int> st;
  vector<int> h(n);
  rep(i, n) { cin >> h[i]; }
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    int x, y;
    x = h[a - 1];
    y = h[b - 1];
    int mn = min(x, y);
    if (x == y) {
      st.insert(a);
      st.insert(b);
    } else if (mn == x) {
      st.insert(a);
    } else if (mn == y) {
      st.insert(b);
    }
  }
  cnt -= st.size();
  cout << cnt << endl;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, r, a, b;
  int c = 0;
  cin >> n >> r;
  vector<int> h(n);
  vector<int> l(n);
  for (int i = 0; i < n; i++) {
    cin >> h.at(i);
    l.at(i) = 1;
  }
  for (int i = 0; i < r; i++) {
    cin >> a >> b;
    if (h.at(a) < h.at(b)) {
      l.at(b) *= 1, l.at(a) *= 0;
    } else if (h.at(a) > h.at(b)) {
      l.at(a) *= 1, l.at(b) = 0;
    } else {
      l.at(a) *= 0, l.at(b) *= 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (l.at(i) == 1) {
      c++;
    }
  }
  cout << c << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, r, a, b;
  int c = 0;
  cin >> n >> r;
  vector<int> h(n);
  vector<int> l(n);
  for (int i = 0; i < n; i++) {
    cin >> h.at(i);
    l.at(i) = 1;
  }
  for (int i = 0; i < r; i++) {
    cin >> a >> b;
    a -= 1, b -= 1;
    if (h.at(a) < h.at(b)) {
      l.at(b) *= 1, l.at(a) *= 0;
    } else if (h.at(a) > h.at(b)) {
      l.at(a) *= 1, l.at(b) = 0;
    } else {
      l.at(a) *= 0, l.at(b) *= 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (l.at(i) == 1) {
      c++;
    }
  }
  cout << c << endl;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
vector<pair<string, P>> vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long N, long long M, std::vector<long long> H,
           std::vector<long long> A, std::vector<long long> B) {
  vector<bool> b(N, true);
  rep(i, N) {
    if (H[A[i]] <= H[B[i]])
      b[A[i]] = false;
    if (H[B[i]] <= H[A[i]])
      b[B[i]] = false;
  }
  ll res = 0;
  rep(i, N) {
    if (b[i])
      res++;
  }
  cout << res << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> H(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &H[i]);
  }
  std::vector<long long> A(M);
  std::vector<long long> B(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
    A[i]--;
    B[i]--;
  }
  solve(N, M, std::move(H), std::move(A), std::move(B));
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
vector<pair<string, P>> vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long N, long long M, std::vector<long long> H,
           std::vector<long long> A, std::vector<long long> B) {
  vector<bool> b(N, true);
  rep(i, M) {
    if (H[A[i]] <= H[B[i]])
      b[A[i]] = false;
    if (H[B[i]] <= H[A[i]])
      b[B[i]] = false;
  }
  ll res = 0;
  rep(i, N) {
    if (b[i])
      res++;
  }
  cout << res << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> H(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &H[i]);
  }
  std::vector<long long> A(M);
  std::vector<long long> B(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
    A[i]--;
    B[i]--;
  }
  solve(N, M, std::move(H), std::move(A), std::move(B));
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

vector<int> adj[123456];
vector<int> hs;

bool is_good(int x) {
  for (int node : adj[x]) {
    if (hs[node] >= hs[x])
      return false;
  }
  return true;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, h;
  cin >> n >> m >> h;
  hs.resize(n + 1);
  for (int i = 1; i <= n; ++i)
    cin >> hs[i];
  for (int i = 0, x, y; i < m; ++i) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    cnt += is_good(i);
  }
  cout << cnt << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

vector<int> adj[123456];
vector<int> hs;

bool is_good(int x) {
  for (int node : adj[x]) {
    if (hs[node] >= hs[x])
      return false;
  }
  return true;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, h;
  cin >> n >> m;
  hs.resize(n + 1);
  for (int i = 1; i <= n; ++i)
    cin >> hs[i];
  for (int i = 0, x, y; i < m; ++i) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    cnt += is_good(i);
  }
  cout << cnt << endl;
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {

  int ans = 0;

  int N, M;
  cin >> N >> M;

  vector<ll> H(N);
  rep(i, N) { cin >> H[i]; }

  vector<int> good(N, 1);

  rep(i, M) {
    int a, b;
    cin >> a >> b;
    good[min(H[a], H[b])] = 0;
  }

  rep(i, N) { ans += good[i]; }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {

  int ans = 0;

  int N, M;
  cin >> N >> M;

  vector<ll> H(N);
  rep(i, N) { cin >> H[i]; }

  vector<int> good(N, 1);

  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (H[a] > H[b]) {
      good[b] = 0;
    } else if (H[a] < H[b]) {
      good[a] = 0;
    } else {
      good[a] = 0;
      good[b] = 0;
    }
  }

  rep(i, N) { ans += good[i]; }

  cout << ans << endl;

  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int main() {
  bool r[100000];
  int h[100000], a[100000], b[100000], n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    r[i] = true;
  }
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }

  for (int i = 0; i < n; i++) {
    auto dif = h[a[i] - 1] - h[b[i] - 1];
    if (dif > 0) {
      r[b[i] - 1] = false;
    } else if (dif < 0) {
      r[a[i] - 1] = false;
    } else {
      r[a[i] - 1] = false;
      r[b[i] - 1] = false;
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (r[i]) {
      cnt++;
    }
  }

  cout << cnt << endl;
}

Fixed submission:
#include <iostream>
using namespace std;

int main() {
  bool r[100000];
  int h[100000], a[100000], b[100000], n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    r[i] = true;
  }
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }

  for (int i = 0; i < m; i++) {
    auto dif = h[a[i] - 1] - h[b[i] - 1];
    if (dif > 0) {
      r[b[i] - 1] = false;
    } else if (dif < 0) {
      r[a[i] - 1] = false;
    } else {
      r[a[i] - 1] = false;
      r[b[i] - 1] = false;
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (r[i]) {
      cnt++;
    }
  }

  cout << cnt << endl;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
int h[100010];
bool flag[100010];
vector<int> vec[100000];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> h[i + 1];
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    vec[a].push_back(b);
    vec[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    if (flag[i])
      continue;
    for (int j = 0; j < vec[i].size(); j++) {
      if (h[i] > h[vec[i][j]]) {
        flag[vec[i][j]] = true;
      } else {
        flag[i] = true;
        break;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!flag[i])
      ans++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
int h[100010];
bool flag[100010];
vector<int> vec[100010];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> h[i + 1];
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    vec[a].push_back(b);
    vec[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    if (flag[i])
      continue;
    for (int j = 0; j < vec[i].size(); j++) {
      if (h[i] > h[vec[i][j]]) {
        flag[vec[i][j]] = true;
      } else {
        flag[i] = true;
        break;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!flag[i])
      ans++;
  }
  cout << ans << endl;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
using Graph = vector<vector<int>>;
using edge = struct {
  int to;
  ll cost;
};
template <class t, class u> void chmax(t &a, u b) {
  if (a < b)
    a = b;
}
template <class t, class u> void chmin(t &a, u b) {
  if (b < a)
    a = b;
}
typedef priority_queue<ll> PQ_HIGH;
typedef priority_queue<ll, VL, greater<ll>> PQ_LOW; // 昇順

int main() {
  int N, M;
  cin >> N >> M;
  VL H(N, 0);
  VI a(N, 0), b(N, 0);
  REP(i, N) { cin >> H[i]; }
  REP(i, M) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
  }
  VI ans(N, 0);
  for (int i = 0; i < M; i++) {
    if (H[a[i]] >= H[b[i]]) {
      ans[b[i]] = 1;
    }
    if (H[a[i]] <= H[b[i]]) {
      ans[a[i]] = 1;
    }
  }
  int count = 0;
  REP(i, N) {
    if (ans[i] == 0) {
      count++;
    }
  }
  cout << count << endl;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
using Graph = vector<vector<int>>;
using edge = struct {
  int to;
  ll cost;
};
template <class t, class u> void chmax(t &a, u b) {
  if (a < b)
    a = b;
}
template <class t, class u> void chmin(t &a, u b) {
  if (b < a)
    a = b;
}
typedef priority_queue<ll> PQ_HIGH;
typedef priority_queue<ll, VL, greater<ll>> PQ_LOW; // 昇順

int main() {
  int N, M;
  cin >> N >> M;
  VL H(N, 0);
  VI a(M, 0), b(M, 0);
  REP(i, N) { cin >> H[i]; }
  REP(i, M) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
  }
  VI ans(N, 0);
  for (int i = 0; i < M; i++) {
    if (H[a[i]] >= H[b[i]]) {
      ans[b[i]] = 1;
    }
    if (H[a[i]] <= H[b[i]]) {
      ans[a[i]] = 1;
    }
  }
  int count = 0;
  REP(i, N) {
    if (ans[i] == 0) {
      count++;
    }
  }
  cout << count << endl;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;

int main() {
  int N, M, A, B;
  int buf[10001];
  int check[10001];

  cin >> N >> M;
  int ans = N;

  for (int i = 1; i <= N; i++) {
    cin >> buf[i];
    check[i] = 0;
  }
  for (int i = 0; i < M; i++) {
    cin >> A >> B;
    // cout << i <<  " ";
    if (buf[A] < buf[B]) {
      // cout << "a" << endl;
      if (check[A] == 0) {
        ans--;
        check[A] = 1;
      }
    } else if (buf[A] == buf[B]) {
      // cout << "b" << endl;
      if (check[A] == 0) {
        ans--;
        check[A] = 1;
      }
      if (check[B] == 0) {
        ans--;
        check[B] = 1;
      }
    } else if (buf[A] > buf[B]) {
      // cout << "c" << endl;
      if (check[B] == 0) {
        ans--;
        check[B] = 1;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;

int main() {
  int N, M, A, B;
  int buf[100001];
  int check[100001];

  cin >> N >> M;
  int ans = N;

  for (int i = 1; i <= N; i++) {
    cin >> buf[i];
    check[i] = 0;
  }
  for (int i = 0; i < M; i++) {
    cin >> A >> B;
    // cout << i <<  " ";
    if (buf[A] < buf[B]) {
      // cout << "a" << endl;
      if (check[A] == 0) {
        ans--;
        check[A] = 1;
      }
    } else if (buf[A] == buf[B]) {
      // cout << "b" << endl;
      if (check[A] == 0) {
        ans--;
        check[A] = 1;
      }
      if (check[B] == 0) {
        ans--;
        check[B] = 1;
      }
    } else if (buf[A] > buf[B]) {
      // cout << "c" << endl;
      if (check[B] == 0) {
        ans--;
        check[B] = 1;
      }
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, M;
  cin >> N;
  cin >> M;
  vector<long> height(N);
  vector<bool> good(N, true);
  vector<vector<bool>> adj(N, vector<bool>(N, false));
  for (int i = 0; i < N; ++i) {
    cin >> height[i];
  }
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a;
    cin >> b;
    a--;
    b--;
    if (height[a] < height[b]) {
      good[a] = false;
    } else if (height[b] < height[a]) {
      good[b] = false;
    } else if (height[a] == height[b]) {
      good[a] = false;
      good[b] = false;
    }
  }

  int ngood = 0;
  for (int i = 0; i < N; ++i) {
    if (good[i])
      ngood++;
  }
  cout << ngood << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, M;
  cin >> N;
  cin >> M;
  vector<long> height(N);
  vector<bool> good(N, true);
  for (int i = 0; i < N; ++i) {
    cin >> height[i];
  }
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a;
    cin >> b;
    a--;
    b--;
    if (height[a] < height[b]) {
      good[a] = false;
    } else if (height[b] < height[a]) {
      good[b] = false;
    } else if (height[a] == height[b]) {
      good[a] = false;
      good[b] = false;
    }
  }

  int ngood = 0;
  for (int i = 0; i < N; ++i) {
    if (good[i])
      ngood++;
  }
  cout << ngood << endl;
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define int long long
#define lowbit(x) ((x) & (-x))
#define hh putchar('\n')
#define kg putchar(' ')
using namespace std;
const int maxn = 10005, mod = 20101009;
int n, m, cnt, head[maxn], h[maxn], ans;
struct edge {
  int to, next;
} e[maxn << 1];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
inline void write(int a) {
  if (a < 0) {
    putchar('-');
    putchar('1');
  } else {
    if (a >= 10)
      write(a / 10);
    putchar(a % 10 + '0');
  }
}
void add(int from, int to) {
  e[++cnt] = (edge){to, head[from]};
  head[from] = cnt;
}
signed main() {
  n = read(), m = read();
  for (int i = 1; i <= n; ++i)
    h[i] = read();
  for (int i = 1; i <= m; ++i) {
    int u = read(), v = read();
    add(u, v), add(v, u);
  }
  for (int i = 1; i <= n; ++i) {
    int flag = 0;
    for (int j = head[i]; j; j = e[j].next)
      if (h[e[j].to] >= h[i]) {
        flag = 1;
        break;
      }
    if (!flag)
      ++ans;
  }
  write(ans);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define int long long
#define lowbit(x) ((x) & (-x))
#define hh putchar('\n')
#define kg putchar(' ')
using namespace std;
const int maxn = 100005, mod = 20101009;
int n, m, cnt, head[maxn], h[maxn], ans;
struct edge {
  int to, next;
} e[maxn << 1];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
inline void write(int a) {
  if (a < 0) {
    putchar('-');
    putchar('1');
  } else {
    if (a >= 10)
      write(a / 10);
    putchar(a % 10 + '0');
  }
}
void add(int from, int to) {
  e[++cnt] = (edge){to, head[from]};
  head[from] = cnt;
}
signed main() {
  n = read(), m = read();
  for (int i = 1; i <= n; ++i)
    h[i] = read();
  for (int i = 1; i <= m; ++i) {
    int u = read(), v = read();
    add(u, v), add(v, u);
  }
  for (int i = 1; i <= n; ++i) {
    int flag = 0;
    for (int j = head[i]; j; j = e[j].next)
      if (h[e[j].to] >= h[i]) {
        flag = 1;
        break;
      }
    if (!flag)
      ++ans;
  }
  write(ans);
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> h(n);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  vector<pair<int, int>> v(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v[i] = mp(a, b);
  }
  vector<bool> ans(n, true);
  for (int i = 0; i < m; i++) {
    if (h[v[i].F - 1] > h[v[i].S - 1]) {
      ans[v[i].S - 1] = false;
    } else if (h[v[i].F - 1] < h[v[i].S - 1]) {
      ans[v[i].F - 1] = false;
    } else {
      ans[v[i].F - 1] = false;
      ans[v[i].S - 1] = false;
    }
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (ans[i] == true)
      count++;
  }
  cout << count << endl;
  return 0;
}


Fixed submission:
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> h(n);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  vector<pair<int, int>> v(m);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v[i] = mp(a, b);
  }
  vector<bool> ans(n, true);
  for (int i = 0; i < m; i++) {
    if (h[v[i].F - 1] > h[v[i].S - 1]) {
      ans[v[i].S - 1] = false;
    } else if (h[v[i].F - 1] < h[v[i].S - 1]) {
      ans[v[i].F - 1] = false;
    } else {
      ans[v[i].F - 1] = false;
      ans[v[i].S - 1] = false;
    }
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (ans[i] == true)
      count++;
  }
  cout << count << endl;
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
/**
 *    author:  Dooloper
 *    created: 03.05.2020 21:47:14
 **/

#include <bits/stdc++.h>

using namespace std;

int cnt[105];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n, m, ans = 0;
  cin >> n >> m;
  vector<long long> h(n);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  for (int i = 0; i < n; i++)
    cnt[i] = 1;

  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    b--;

    if (h[a] >= h[b] && cnt[b] != 0) {
      cnt[b] = 0;
    }
    if (h[a] <= h[b] && cnt[a] != 0) {
      cnt[a] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (cnt[i] == 1)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
/**
 *    author:  Dooloper
 *    created: 03.05.2020 21:47:14
 **/

#include <bits/stdc++.h>

using namespace std;

int cnt[101010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n, m, ans = 0;
  cin >> n >> m;
  vector<long long> h(n);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  for (int i = 0; i < n; i++)
    cnt[i] = 1;

  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    b--;

    if (h[a] >= h[b] && cnt[b] != 0) {
      cnt[b] = 0;
    }
    if (h[a] <= h[b] && cnt[a] != 0) {
      cnt[a] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (cnt[i] == 1)
      ans++;
  }
  cout << ans << endl;
  return 0;
}